南方移民问题

2024-04-24 20:36:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经看了这些问题;http://south.readthedocs.org/en/latest/tutorial/part1.htmlSouth ignores change in field default value in Python / Django&;Django-south not detecting DB changes以及更多的问题,所以我似乎无法解决我的问题。你知道吗

我有一个现有的模型,它的表中有数据,我正在通过外键向它添加另一个模型。我已经运行了一次又一次的模式迁移,但没有任何结果。代码如下:

class UserNote(models.Model):
   user = models.ForeignKey(User)
   description = models.TextField(blank=True, null=True)

   created_at = models.DateTimeField(auto_now_add=True)
   updated_at = models.DateTimeField(auto_now=True)



class UserNoteType(models.Model):
    name = models.CharField(max_length=20)

我需要将UserNoteType作为外键添加到UserNote中,每次尝试添加字段都会导致“not installed”、“not defined”。我已经为此奋斗了好几个小时了,任何帮助都会大有裨益。你知道吗

编辑: 尝试创建架构迁移时收到的错误:

CommandError:一个或多个模型未验证: 身份验证用户注释:“note_type”与model有关系,model要么尚未安装,要么是抽象的。你知道吗


Tags: djangoin模型trueautomodelmodelsnot
3条回答

UserNote模型附加到Django UserAuth应用程序。这导致South每次都在错误的应用程序中查找。我通过创建一个自定义命令将新的列note类型手动插入到UserNote表中,解决了这个问题。你知道吗

非常感谢你的帮助。你知道吗

供参考

如果您正在创建一个新项目,那么从它自己开始,您需要设置south,请尝试以下操作:

python manage.py syncdb

python manage.py schemamigration  initial firstapp

python manage.py migrate forecasts  fake


python manage.py schemamigration  auto firstapp

python manage.py migrate google

在开发端之后,您计划包含south,然后尝试下面的方法

./manage.py schemamigration  auto firstapp

./manage.py migrate firstapp

您是否尝试使用以下命令将现有的应用程序转换为South?你知道吗

python manage.py convert_to_south my_app

更多信息请参见here

相关问题 更多 >