#24506: Proxying User model creates an invalid migration
----------------------------------------------+--------------------
Reporter: tinloaf | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Hi!
I have created a proxy model for the User model like this (in
core.models):
{{{
from django.contrib.auth.models import User as OriginalUser
class User(OriginalUser):
objects = UserManager()
all_objects = AllUserManager()
class Meta:
proxy = True
[...]
}}}
I then changed some ForeignKeys that have been pointing to the original
User to my proxy. Now makemigrations creates a migration that looks like
this:
{{{
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('finance', '0011_auto_20141126_1447'),
]
operations = [
migrations.AlterField(
model_name='financialdata',
name='user',
field=models.OneToOneField(to='core.User'),
preserve_default=True,
),
migrations.AlterField(
model_name='mandate',
name='user',
field=models.ForeignKey(to='core.User'),
preserve_default=True,
),
migrations.AlterField(
model_name='userrate',
name='user',
field=models.ForeignKey(to='core.User'),
preserve_default=True,
),
]
}}}
Which looks OK so far. If I try to run this migration, it fails like this:
{{{
(venv)tinloaf@janeway alumnet % python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: gis, bootstrap3, dajaxice,
autocomplete_light
Apply all migrations: sessions, ml, auth, admin, local, finance, core,
contenttypes
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying finance.0012_auto_20150319_1316...Traceback (most recent call
last):
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/apps/registry.py", line 148, in get_app_config
return self.app_configs[app_label]
KeyError: 'core'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/db/migrations/state.py", line 84, in render
model = self.apps.get_model(lookup_model[0], lookup_model[1])
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/apps/registry.py", line 202, in get_model
return self.get_app_config(app_label).get_model(model_name.lower())
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/apps/registry.py", line 150, in get_app_config
raise LookupError("No installed app with label '%s'." % app_label)
LookupError: No installed app with label 'core'.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/core/management/__init__.py", line 385, in
execute_from_command_line
utility.execute()
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/core/management/commands/migrate.py", line 161, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/db/migrations/executor.py", line 68, in migrate
self.apply_migration(migration, fake=fake)
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/db/migrations/executor.py", line 96, in apply_migration
if self.detect_soft_applied(migration):
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/db/migrations/executor.py", line 140, in
detect_soft_applied
apps = project_state.render()
File "/mnt/data/home/tinloaf/src/alumnet/venv/lib/python3.3/site-
packages/django/db/migrations/state.py", line 94, in render
raise ValueError(msg.format(field=operations[0][1],
model=lookup_model))
ValueError: Lookup failed for model referenced by field
finance.FinancialData.user: core.User
}}}
So, for some reason, it cannot find the core module and/or the core.User
model. The core module is in my installed apps, and the whole application
works if I just fake the migration, so the model itself works, etc. Still,
having to fake a migration in this case should probably not be the
intended solution.
Also, I can't fake that migration in tests, making testing essentially
impossible in this case.
--
Ticket URL: <https://code.djangoproject.com/ticket/24506>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.db27e3526e6de9a12ce3df7de0b02b7e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.