3

Due to merging several feature branches into my project, I have the following migrations:

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

Note that I have two duplicate 0005 migrations. These ran fine, and deployed fine on my production system.

$ 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

My table has the correct columns:

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

However, if I try to create a new migration, South thinks that I haven't added the column' permitted_domains' to my model:

$ 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

How do I fix this?

4

2 回答 2

3

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

当自动检测器运行时,它会将您当前的模型与您最近在应用程序上迁移中冻结的模型进行比较,如果发现任何更改,则会向 South migration-file-writer 生成一个或多个操作。

迁移将模型中字段的冻结版本保存在字典中。

所以:

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,从而导致南第二次添加该字段。

如果您将“permitted_domains”字段的行从中复制0005_auto__add_field_organisation_permitted_domains0005_auto__add_field_userprofile_currency这将解决您的问题。

于 2013-05-14T16:24:10.937 回答
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 中的南方引擎

希望这可以帮助!

于 2013-05-14T16:29:36.727 回答