#22325: Defining a custom user model in an app and having relations between it 
and
other models in the app causes circular dependencies
----------------------------+--------------------
     Reporter:  melinath    |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Migrations  |    Version:  master
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+--------------------
 I *think* the issue is that swappable_dependency resolves to
 app_label.__first__, which doesn't make a lot of sense when the app with
 the migrations is itself being migrated. Removing that line seems to
 temporarily resolve the issue, but if my app were ever used with a
 *different* AUTH_USER_MODEL, it would then presumably break again. (Also,
 I still get a circular dependency in the next migration that defines a
 relation to AUTH_USER_MODEL.)

 Here are the important bits from *one* migration:

 {{{
 class Migration(migrations.Migration):

     dependencies = [
         migrations.swappable_dependency(settings.AUTH_USER_MODEL),
         ('app_label', '0002_blah_blah'),
     ]

     operations = [
         migrations.CreateModel(
             # This is the AUTH_USER_MODEL
             name='Person',
             fields=[
                 ...
             ],
             options={
                 u'verbose_name': u'person',
                 u'verbose_name_plural': u'people',
             },
             bases=(models.Model,),
         ),
         migrations.CreateModel(
             name='PersonDiscount',
             fields=[
                 ...
                 ('person', models.ForeignKey(to=settings.AUTH_USER_MODEL,
 to_field=u'id')),
             ],
             options={
             },
             bases=(models.Model,),
         ),
     ]
 }}}

 Traceback:

 {{{
 Traceback (most recent call last):
   File "./manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
   File ".../django/django/core/management/__init__.py", line 427, in
 execute_from_command_line
     utility.execute()
   File ".../django/django/core/management/__init__.py", line 419, in
 execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File ".../django/django/core/management/base.py", line 288, in
 run_from_argv
     self.execute(*args, **options.__dict__)
   File ".../django/django/core/management/base.py", line 337, in execute
     output = self.handle(*args, **options)
   File ".../django/django/core/management/commands/migrate.py", line 103,
 in handle
     plan = executor.migration_plan(targets)
   File ".../django/django/db/migrations/executor.py", line 46, in
 migration_plan
     for migration in self.loader.graph.forwards_plan(target):
   File ".../django/django/db/migrations/graph.py", line 53, in
 forwards_plan
     return self.dfs(node, lambda x: self.dependencies.get(x, set()))
   File ".../django/django/db/migrations/graph.py", line 119, in dfs
     return _dfs(start, get_children, [])
   File ".../django/django/db/migrations/graph.py", line 111, in _dfs
     results = _dfs(n, get_children, path) + results
   File ".../django/django/db/migrations/graph.py", line 111, in _dfs
     results = _dfs(n, get_children, path) + results
   File ".../django/django/db/migrations/graph.py", line 111, in _dfs
     results = _dfs(n, get_children, path) + results
   File ".../django/django/db/migrations/graph.py", line 103, in _dfs
     raise CircularDependencyError(path[path.index(start):] + [start])
 django.db.migrations.graph.CircularDependencyError: [('brambling',
 '0003_blah_blah'), ('brambling', '0003_blah_blah')]
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22325>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.509d37ddc36be23958219e1aadc3a18d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to