﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22542	Migrations introduce circular dependency on custom user model	hoha@…	nobody	"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."	Bug	closed	Migrations	1.7-beta-2	Normal	duplicate			Unreviewed	0	0	0	0	0	0
