[Django] #21142: Referencing the User model and migrations

103 views
Skip to first unread message

Django

unread,
Sep 22, 2013, 4:28:08 PM9/22/13
to django-...@googlegroups.com
#21142: Referencing the User model and migrations
---------------------------------+-----------------------------
Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Keywords: Migration, Auth
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------
Hi,

To verify this bug I use a very simple model in which I reference to the
User model:

{{{
from django.conf import settings
from django.db import models


class Article(models.Model):
name = models.CharField('Name', max_length=255)
author = models.ForeignKey(settings.AUTH_USER_MODEL)
}}}

After running ./manage.py makemigrations everything looks fine:

{{{
Do you want to enable migrations for app 'articles'? [y/N] y
Migrations for 'articles':
0001_initial.py:
- Create model Article
}}}

But running ./manage.py migrate runs into following error:

{{{
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/mario/django-trunk/django/core/management/__init__.py", line
397, in execute_from_command_line
utility.execute()
File "/home/mario/django-trunk/django/core/management/__init__.py", line
390, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/mario/django-trunk/django/core/management/base.py", line
242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/mario/django-trunk/django/core/management/base.py", line
289, in execute
output = self.handle(*args, **options)
File "/home/mario/django-
trunk/django/core/management/commands/migrate.py", line 88, in handle
targets = executor.loader.graph.leaf_nodes()
File "/home/mario/django-trunk/django/utils/functional.py", line 49, in
__get__
res = instance.__dict__[self.func.__name__] = self.func(instance)
File "/home/mario/django-trunk/django/db/migrations/loader.py", line
169, in graph
graph.add_dependency(key, parent)
File "/home/mario/django-trunk/django/db/migrations/graph.py", line 40,
in add_dependency
raise KeyError("Dependency references nonexistent parent node %r" %
(parent,))
KeyError: "Dependency references nonexistent parent node (u'auth',
'0001_initial')"
}}}

The same happens when I directly reference to the User model:

{{{
from django.contrib.auth.models import User
from django.db import models


class Article(models.Model):
name = models.CharField('Name', max_length=255)
author = models.ForeignKey(User)
}}}

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

Django

unread,
Sep 23, 2013, 10:26:22 AM9/23/13
to django-...@googlegroups.com
#21142: Referencing the User model and migrations
---------------------------------+------------------------------------

Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: Migration, Auth | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by bmispelon):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

Hi,

I can reproduce the issue and from what I can tell, you're following the
documentation (both for referencing the user model and for making/applying
migrations) so this is most likely a bug.

Thanks for the detailed report.

--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:1>

Django

unread,
Oct 13, 2013, 2:24:08 PM10/13/13
to django-...@googlegroups.com
#21142: Referencing the User model and migrations
---------------------------------+------------------------------------

Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: Migration, Auth | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by OBu):

I just ran into the same problem.
To add one more detail to the problem description:

0001_initial.py starts with
class Migration(migrations.Migration):

dependencies = [(u'auth', '0001_initial'), (u'my_app_name',
'__first__')]

--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:2>

Django

unread,
Oct 16, 2013, 1:26:36 PM10/16/13
to django-...@googlegroups.com
#21142: Cannot run migrations that reference django.contrib.auth.models.User
---------------------------------+------------------------------------

Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: Migration, Auth | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by timo):

I've looked into adding migrations to `contrib.auth`, but ran into #21275.
It's also unclear how migrations are supposed to work with "swappable"
models like `User`. Obviously, we want to ignore it if a project uses a
custom user.

--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:3>

Django

unread,
Oct 17, 2013, 6:42:02 PM10/17/13
to django-...@googlegroups.com
#21142: Cannot run migrations that reference django.contrib.auth.models.User
---------------------------------+------------------------------------
Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: Migration, Auth | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by OBu):

...and to add to the list of problems: There is no migration `__first__`as
well.
Removing the dependencies does not help since migrate is checking all
foreign keys and it does not find information about foreign keys pointing
to `Users`.

Since tried to add a `--fake` migration since in my current application I
wanted to add just a boolean, but this still did not help since migrate
traverses through all models fields.

To sum it up: No work arounds found, switching back to south :-(...

I don't have too much experience with django core development, but I would
rate this bug a "release blocker"...

--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:4>

Django

unread,
Oct 17, 2013, 7:08:07 PM10/17/13
to django-...@googlegroups.com
#21142: Cannot run migrations that reference django.contrib.auth.models.User
---------------------------------+------------------------------------
Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: Migration, Auth | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by timo):

Yes, migrations is still under active development. It was merged well
before it was feature complete because reconciling changes on master with
the external branch was a challenge. We will definitely review all
migrations tickets before releasing 1.7.

--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:5>

Django

unread,
Oct 23, 2013, 9:46:55 AM10/23/13
to django-...@googlegroups.com
#21142: Cannot run migrations that reference django.contrib.auth.models.User
---------------------------------+------------------------------------
Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: Migration, Auth | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by timo):

From Andrew on IRC: "My plan was that contrib apps would ship with
migrations. Specifically, I'd like to ship auth with some straight in 1.7.
Initial fake migrations will be handled by the new framework directly."

So this bug should be fixed in due time before the 1.7 release. Thanks for
your patience.

--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:6>

Django

unread,
Nov 1, 2013, 7:45:54 PM11/1/13
to django-...@googlegroups.com
#21142: Cannot run migrations that reference django.contrib.auth.models.User
---------------------------------+------------------------------------
Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: Migration, Auth | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by OBu):

Timo, thanks for keeping us updated! I'm really looking forward to the new
migration system!

--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:7>

Django

unread,
Nov 1, 2013, 7:46:12 PM11/1/13
to django-...@googlegroups.com
#21142: Cannot run migrations that reference django.contrib.auth.models.User
---------------------------------+------------------------------------
Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: Migration, Auth | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by OBu):

* cc: OBu (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:8>

Django

unread,
Nov 26, 2013, 3:48:08 PM11/26/13
to django-...@googlegroups.com
#21142: Cannot run migrations that reference django.contrib.auth.models.User
---------------------------------+------------------------------------
Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: Migration, Auth | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by andrewgodwin):

Yes, sorry, you probably hit a part of the dependency resolution that was
failing. It's supposed to depend on __first__, which if the application
doesn't have migrations is ignored - I'll make sure it's doing that.

--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:9>

Django

unread,
Nov 27, 2013, 5:56:54 AM11/27/13
to django-...@googlegroups.com
#21142: Cannot run migrations that reference django.contrib.auth.models.User
---------------------------------+------------------------------------
Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: Migration, Auth | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by robin):

* cc: robinchew@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:10>

Django

unread,
Dec 19, 2013, 1:40:29 AM12/19/13
to django-...@googlegroups.com
#21142: Cannot run migrations that reference django.contrib.auth.models.User
---------------------------------+------------------------------------
Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: Migration, Auth | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by zxc.spam@…):

* cc: zxc.spam@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:11>

Django

unread,
Dec 22, 2013, 4:09:58 PM12/22/13
to django-...@googlegroups.com
#21142: Cannot run migrations that reference django.contrib.auth.models.User
---------------------------------+------------------------------------
Reporter: mario.pfeifer@… | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: Migration, Auth | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by ajendrex):

* cc: ajendrex (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:12>

Django

unread,
Jan 8, 2014, 8:00:57 AM1/8/14
to django-...@googlegroups.com
#21142: Cannot run migrations that reference django.contrib.auth.models.User
-------------------------------------+-------------------------------------
Reporter: mario.pfeifer@… | Owner: Andrew
Type: Bug | Godwin <andrew@…>
Component: Migrations | Status: closed
Severity: Normal | Version: master
Keywords: Migration, Auth | Resolution: fixed
Has patch: 0 | Triage Stage: Accepted
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Andrew Godwin <andrew@…>):

* owner: => Andrew Godwin <andrew@…>
* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"64887c644a8fe1004a15e27087d4e27c95c90fcd"]:
{{{
#!CommitTicketReference repository=""
revision="64887c644a8fe1004a15e27087d4e27c95c90fcd"
Fixed #21142: Dependency failures on unmigrated apps.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:13>

Django

unread,
Jan 8, 2014, 9:45:48 AM1/8/14
to django-...@googlegroups.com
#21142: Cannot run migrations that reference django.contrib.auth.models.User
-------------------------------------+-------------------------------------
Reporter: mario.pfeifer@… | Owner: Andrew
Type: Bug | Godwin <andrew@…>
Component: Migrations | Status: closed
Severity: Normal | Version: master
Keywords: Migration, Auth | Resolution: fixed
Has patch: 0 | Triage Stage: Accepted
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by anthony.arnold@…):

Was ''just'' Googling this error and discovered that it was pulled to
master an hour and a half ago. Thanks, Internet.

--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:14>

Reply all
Reply to author
Forward
0 new messages