I have 2 django apps i.e. main and authtools. When I run
python manage.py migrate
, I get a CircularDependencyError:
raise CircularDependencyError(", ".join("%s.%s" % n for n in cycle))
django.db.migrations.graph.CircularDependencyError: main.0001_initial, authtools.0001_initial
In my setting file I have the AUTH_USER_MODEL defined as such:AUTH_USER_MODEL = 'authtools.User'
. The migration files created look like this:
For the authtools app, it shows dependancies as:
dependencies = [
('main', '__first__'),
('auth', '0001_initial'),
]
And for the main app, the depandancies are shown as:
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
What could be wrong?
If you use ManyToMany + 'through' option to different application, than according to this answer you should:
If you dont use ManyToMany, than according to this answer, try similar actions.
Lets suppose that you want to create these models:
libros/models.py:
class Libro(models.Model):
name = models.CharField(max_length=20)
perfile = models.ForeignKey('perfiles.Perfile', null=True)
perfiles/models.py:
class Perfile(models.Model):
name = models.CharField(max_length=20)
libro = models.ForeignKey('libros.Libro', null=True)
Of course you can't do it because of the circular dependency. So comment out foreign key in the Libro
model:
class Libro(models.Model):
name = models.CharField(max_length=20)
# perfile = models.ForeignKey('perfiles.Perfile', null=True)
And run two migrations:
python manage.py makemigrations libros
python manage.py makemigrations perfiles
After that uncomment the perfile
foreign key in the Libro
model and run another migration:
python manage.py makemigrations libros
I think you need to follow this ticket of django code base: https://code.djangoproject.com/ticket/22932
According to them your migration code should look like either this (https://code.djangoproject.com/attachment/ticket/22932/team.0001_initial.py.diff) or(https://code.djangoproject.com/attachment/ticket/22932/team.0002_auto_20140704_1453.py):
# -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 from django.db import models, migrations
5 from django.conf import settings
6
7
8 class Migration(migrations.Migration):
9
10 dependencies = [
11 migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12 ('team', '0001_initial'),
13 ]
14
15 operations = [
16 migrations.CreateModel(
17 name='TeamCaptain',
18 fields=[
19 ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
20 ('rider', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
21 ('team', models.ForeignKey(to='team.Team')),
22 ],
23 options={
24 },
25 bases=(models.Model,),
26 ),
27 ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With