#21142 closed Bug (fixed)
Cannot run migrations that reference django.contrib.auth.models.User
Reported by: | Owned by: | ||
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | Migration, Auth |
Cc: | OBu, robinchew@…, zxc.spam@…, Héctor Urbina | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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)
Change History (14)
comment:1 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 11 years ago
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')]
comment:3 by , 11 years ago
Summary: | Referencing the User model and migrations → Cannot run migrations that reference django.contrib.auth.models.User |
---|
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.
comment:4 by , 11 years ago
...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"...
comment:5 by , 11 years ago
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.
comment:6 by , 11 years ago
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.
comment:7 by , 11 years ago
Timo, thanks for keeping us updated! I'm really looking forward to the new migration system!
comment:8 by , 11 years ago
Cc: | added |
---|
comment:9 by , 11 years ago
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.
comment:10 by , 11 years ago
Cc: | added |
---|
comment:11 by , 11 years ago
Cc: | added |
---|
comment:12 by , 11 years ago
Cc: | added |
---|
comment:13 by , 11 years ago
Owner: | set to |
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:14 by , 11 years ago
Was just Googling this error and discovered that it was pulled to master an hour and a half ago. Thanks, Internet.
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.