在Django 1.7c2中运行迁移时出现循环依赖性错误

时间:2014-08-13 17:48:18

标签: django django-migrations

我一直在https://docs.djangoproject.com/en/1.7/topics/migrations/阅读有关django迁移的文章。我还回顾了github上1.7.x分支的提交,我明白这个问题可能已经解决了。 不幸的是,在运行迁移时我仍然遇到错误。 --fake选项提供相同的错误。

我有以下迁移:

'人'应用迁移:

user@host$ /manage.py makemigrations people
Migrations for 'people':
0001_initial.py:
- Create model Person
- Create model Committee
- Create model DepartmentGroup
- Add field department_group to person
- Create model MemberType
- Add field member_type to person
- Alter unique_together for person (1 constraint(s))
- Create model PersonCommittee
- Add field committees to committee
- Add field committee to personcommittee
- Add field member to personcommittee
- Alter unique_together for personcommittee (1 constraint(s))
- Create model Role
- Create proxy model PersonArchive

'位置'应用迁移:

user@host$ ./manage.py makemigrations locations
Migrations for 'locations':
0001_initial.py:
- Create model Building
- Create model Institution
- Create model InstitutionAddress
- Add field institution to building
- Add field address to institutionaddress
- Add field institution to institutionaddress
- Create model Room
- Alter unique_together for room (1 constraint(s))

现在我使用

运行迁移
./manage.py migrate

这是我得到的错误

django.db.migrations.graph.CircularDependencyError: 
[('people', u'0001_initial'), ('locations', u'0001_initial'), 
('people', u'0001_initial')]

可以在以下位置查看完整错误:http://pastebin.com/jixK6Ve2

我的问题是,如果django代码中仍然存在需要修复的内容,请参阅固定票证:https://code.djangoproject.com/ticket/22932。如果没有,是否可以选择以2个或更多步骤拆分迁移以避免循环依赖性错误?

1 个答案:

答案 0 :(得分:5)

来自https://code.djangoproject.com/ticket/22932#comment:4的用户humitos指示的步骤似乎解决了这个问题。

我基本上需要删除可交换的依赖项和冲突的模型,并将它们放入一个新的空迁移中。