【问题标题】:Recovering from a duplicate migration in Django South从 Django South 中的重复迁移中恢复
【发布时间】:2013-05-14 16:17:06
【问题描述】:

由于将几个功能分支合并到我的项目中,我有以下迁移:

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

我该如何解决这个问题?

【问题讨论】:

    标签: python django django-south


    【解决方案1】:

    来自文档: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 中的字段记录进行比较,从而导致向南第二次添加该字段。

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

    【讨论】:

    • 对于其他提到这个的人:不要忘记从south_migrationhistory表中删除折叠的迁移(即0005_auto__add_field_organisation_permitted_domains),否则运行时会出现此错误@ 987654331@:I'm not trusting myself; either fix this yourself by fiddling with the south_migrationhistory table, or pass --delete-ghost-migrations to South to have it delete ALL of these records (this may not be good).
    【解决方案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 中的南引擎

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2014-01-11
      • 2015-05-06
      • 2016-11-21
      • 1970-01-01
      • 2018-02-22
      • 2023-03-14
      • 2012-08-06
      • 2012-08-13
      • 1970-01-01
      相关资源
      最近更新 更多