南移民问题

时间:2014-07-25 13:26:47

标签: python django postgresql database-migration django-south

我看过这些问题; 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,并且每次添加该字段的尝试都会导致“未安装”,“未定义”。我已经和我斗争了几个小时了,任何帮助都会有很大帮助。

编辑: 我在尝试创建模式迁移时收到错误:

CommandError:一个或多个模型未验证: auth.usernote:'note_type'与model有关系,该模型尚未安装或是抽象的。

3 个答案:

答案 0 :(得分:0)

您是否尝试使用以下命令将现有应用转换为South?

python manage.py convert_to_south my_app

可以找到更多信息here

答案 1 :(得分:0)

供您参考

如果您正在创建新项目,请自行开始设置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

答案 2 :(得分:0)

UserNote模型已附加到Django UserAuth应用程序。这导致南方每次都在寻找错误的应用程序。我通过创建自定义命令来手动将新列note_type插入UserNote表来修复此问题。

非常感谢你的帮助。