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.
* 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>
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>
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>
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>
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>
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>
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>
* cc: OBu (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:8>
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>
* cc: robinchew@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:10>
* cc: zxc.spam@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:11>
* cc: ajendrex (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/21142#comment:12>
* 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>
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>