修复Django1.9中检测到的冲突迁移

时间:2016-04-15 20:43:43

标签: python django django-models django-migrations

我更新了django-dynamic-model存储库以支持Django 1.9。我收到了这个错误:

CommandError: 

Conflicting migrations detected; multiple leaf nodes in the migration
graph: (0001_initial, 0002_auto__add_field_dynamicschemafield_extra in
dynamicmodel).
To fix them run 'python manage.py makemigrations --merge'

运行python manage.py makemigrations --merge后,又出现了另一个错误:

 File "/local/lib/python2.7/sitepackages/django/core/management/__init__.py",  
line 353, in execute_from_command_line
utility.execute()

 File "/local/lib/python2.7/sitepackages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)

 File 
"/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)

File 
"/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)

File 
"/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 97, in handle
return self.handle_merge(loader, conflicts)

File 
   "/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 216, in handle_merge
 raise ValueError("Could not find common ancestor of %s" % migration_names)


 ValueError: Could not find common ancestor of set([u'0001_initial', u'0002_auto__add_field_dynamicschemafield_extra']). 

帮我找到解决方案。

2 个答案:

答案 0 :(得分:0)

迁移需要"直接"依赖链,即迁移0003需要依赖于迁移0002和0001上的0002。

您需要在0003_third.py中定义此内容,如下所示:

class Migration(migrations.Migration):
    dependencies = [
        ('modulename', '0002_second'),
    ]

答案 1 :(得分:-1)

好像你已经注入了其他应用程序的模型。

在迁移中定义TARGET_APP,似乎迁移加载程序无法正确识别目标应用。