Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Circular dependency error when running migrations in Django 1.7c2

I have been reading about django migrations at https://docs.djangoproject.com/en/1.7/topics/migrations/. I also reviewed the commits on the 1.7.x branch in github where I understand that this problem may have been solved. Unfortunately I still get the error when running my migrations. The --fake option gives the same error.

I have the following migrations:

'people' app migration:

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

'locations' app migration:

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))

Now I run the migrations with

./manage.py migrate

and this is the error I get

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

The full error can be viewed at: http://pastebin.com/jixK6Ve2

My question is if there is still something in the django code that needs to be fixed, see fixed ticket: https://code.djangoproject.com/ticket/22932. If not, is there an option to split the migrations in 2 or more steps to avoid the circular dependency error?

like image 617
jcuot Avatar asked Aug 13 '14 17:08

jcuot


People also ask

How does Django know which migrations to run?

Ensuring that a migration is applied only once requires keeping track of the migrations that have been applied. Django uses a database table called django_migrations . Django automatically creates this table in your database the first time you apply any migrations.

Which command is used for migration in Django?

The Commands There are several commands which you will use to interact with migrations and Django's handling of database schema: migrate , which is responsible for applying and unapplying migrations. makemigrations , which is responsible for creating new migrations based on the changes you have made to your models.


1 Answers

The steps indicated by user humitos from https://code.djangoproject.com/ticket/22932#comment:4 seem to have solved the problem.

I basically needed to remove the swappable dependency and the conflicting model and put them in a new empty migration.

like image 183
jcuot Avatar answered Sep 27 '22 22:09

jcuot