ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python – 从Django South的重复迁移中恢复

2019-09-01 00:07:42  阅读:173  来源: 互联网

标签: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

我该如何解决?

解决方法:

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

When the autodetector runs, it compares your current models with those
frozen in your most recent migration on the app, and if it finds any
changes, yields one or more Actions to the South
migration-file-writer.

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

因此:

在0005_auto__add_field_organisation_permitted_domains中,组织类将具有allowed_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,这将解决您的问题.

标签:python,django,django-south
来源: https://codeday.me/bug/20190831/1779366.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有