Opened 10 years ago

Closed 10 years ago

#22542 closed Bug (duplicate)

Migrations introduce circular dependency on custom user model

Reported by: hoha@… Owned by: nobody
Component: Migrations Version: 1.7-beta-2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It appears that a custom user model which inherits from another model which has foreign keys to the user model, will fail when the migration is run, due to a circular dependency. This code works just fine under Django 1.6 syncdb or South for that matter. The code fails both when the base class is abstract and if not (making it abstract produces an extra migration file though).

Attached is a model file with a custom user model implemented (and set as the AUTH_MODEL in settings).

When makemigrations is run, three migrations are created. Upon appliance it fails with the following traceback:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/henrik/dj17b3/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/Users/henrik/dj17b3/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/henrik/dj17b3/venv/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/henrik/dj17b3/venv/lib/python3.4/site-packages/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/Users/henrik/dj17b3/venv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 103, in handle
    plan = executor.migration_plan(targets)
  File "/Users/henrik/dj17b3/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 36, in migration_plan
    backwards_plan = self.loader.graph.backwards_plan(target)[:-1]
  File "/Users/henrik/dj17b3/venv/lib/python3.4/site-packages/django/db/migrations/graph.py", line 64, in backwards_plan
    return self.dfs(node, lambda x: self.dependents.get(x, set()))
  File "/Users/henrik/dj17b3/venv/lib/python3.4/site-packages/django/db/migrations/graph.py", line 119, in dfs
    return _dfs(start, get_children, [])
  File "/Users/henrik/dj17b3/venv/lib/python3.4/site-packages/django/db/migrations/graph.py", line 111, in _dfs
    results = _dfs(n, get_children, path) + results
  File "/Users/henrik/dj17b3/venv/lib/python3.4/site-packages/django/db/migrations/graph.py", line 111, in _dfs
    results = _dfs(n, get_children, path) + results
  File "/Users/henrik/dj17b3/venv/lib/python3.4/site-packages/django/db/migrations/graph.py", line 103, in _dfs
    raise CircularDependencyError(path[path.index(start):] + [start])
django.db.migrations.graph.CircularDependencyError: [('accounts', '0001_initial'), ('accounts', '0001_initial')]

Tested in Django 1.7b3 (not available to choose in the version list). Personally I'd consider this a release blocker; the functionality worked as expected in Django 1.6. I will let you guys decide on the severity though, obviously.

Attachments (1)

models.py (2.5 KB ) - added by hoha@… 10 years ago.
Model file containing a custom user model

Download all attachments as: .zip

Change History (2)

by hoha@…, 10 years ago

Attachment: models.py added

Model file containing a custom user model

comment:1 by Tim Graham, 10 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #22325

Note: See TracTickets for help on using tickets.
Back to Top