从Django South的重复迁移中恢复

时间:2013-05-14 16:17:06

标签: python django django-south

由于将多个功能分支合并到我的项目中,我进行了以下迁移:

0001_initial.py
0002_auto__add_field_userprofile_telephone__add_field_userprofile_timezone.py
0003_auto.py
0004_auto__del_field_organisation_admin.py
0005_auto__add_field_organisation_permitted_domains.py
0005_auto__add_field_userprofile_currency.py

请注意,我有两次重复的0005迁移。这些运行正常,并且在我的生产系统上部署得很好。

$ python manage.py migrate accounts --list                                                                                                                                                              [17:11:42]

 accounts
  (*) 0001_initial
  (*) 0002_auto__add_field_userprofile_telephone__add_field_userprofile_timezone
  (*) 0003_auto
  (*) 0004_auto__del_field_organisation_admin
  (*) 0005_auto__add_field_organisation_permitted_domains
  (*) 0005_auto__add_field_userprofile_currency

我的表格列正确:

$ psql
db_my_project=# \d+ accounts_organisation
db_my_project=# \d+ accounts_userprofile
... shows currency and permitted_domain, suggesting the migrations worked correctly

但是,如果我尝试创建新的迁移,South认为我没有将“allowed_domains”列添加到我的模型中:

$ python manage.py schemamigration accounts --auto                                                                                                                                                      [17:16:15]
 + Added field permitted_domains on accounts.Organisation
Created 0006_auto__add_field_organisation_permitted_domains.py. You can now apply this migration with: ./manage.py migrate accounts

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:3)

来自文档:http://south.readthedocs.org/en/0.7.6/autodetector.html

  

当自动检测器运行时,它会将您当前的模型与那些模型进行比较   在应用程序的最近迁移中冻结,如果找到则冻结   改变,向南方产生一个或多个行动   迁移文件写入器。

迁移会在模型中保留模型中字段的冻结版本。

因此:

0005_auto__add_field_organisation_permitted_domains中,组织类将包含字段permitted_domains,但在0005_auto__add_field_userprofile_currency中则不会。当你跑:

$ python manage.py schemamigrate accounts --auto

这会将代码的当前状态与0005_auto_add_field_userprofile_currency中的字段存储记录进行比较,从而导致南方第二次添加该字段。

如果您将'allowed_domains'字段的行从0005_auto__add_field_organisation_permitted_domains复制到0005_auto__add_field_userprofile_currency,这将解决您的问题。

答案 1 :(得分:2)

这是一个非常具体的问题,我希望这有帮助,请执行以下操作:

1)将此文件重命名为0005_auto__add_field_organisation_permitted_domains0006_auto__add_field_organisation_permitted_domains

2)将最近迁移文件的编号从0006重命名为0007

3)发出命令python manage.py migrate account 0006 --fake来欺骗南方。

4)发出命令python manage.py migrate account 0007

这可能会再次使用您的应用程序在sycn中获取南引擎

希望这有帮助!

相关问题