My app `myapp` has a model `MyModel` with a couple foreign keys to
`django.contrib.auth.User` (yes, `auth` is in my `INSTALLED_APPS`, despite
what the stack trace below says; notably everything was working fine
before squashing):
{{{#!python
from django.contrib.auth import User
from django.db.models import Model, ForeignKey
class MyModel(Model):
creator = ForeignKey(User, related_name='mymodel_creator_set')
modifier = ForeignKey(User, related_name='mymodel_modifier_set')
# ... and then a bunch of business logic...
}}}
I have a few other models with foreign keys to `User`, but that's the one
that shows up in the stack trace.
I had accumulated 18 migrations, which were slowing down my tests (the
migrations always run at the start of `migrations.py test`, at least when
developing on SQLite). So I ran
{{{
#!bash
(venv) $ ./manage.py squashmigrations myapp 0018
}}}
Then when I ran
{{{
#!bash
(venv) $ rm db.sqlite3 && ./manage.py migrate
}}}
I got the stack trace below. When I deleted the squashed migration and
reran it with `--no-optimize`, I got exactly the same stack trace.
{{{
(venv3) $ rm db.sqlite3 && ./manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, myapp
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying sessions.0001_initial... OK
Applying myapp.0001_squashed_0018_<redacted>...Traceback (most recent
call last):
File ".../django/apps/registry.py", line 136, in get_app_config
return self.app_configs[app_label]
KeyError: 'auth'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".../django/db/migrations/state.py", line 79, in render
model = self.apps.get_model(lookup_model[0], lookup_model[1])
File ".../django/apps/registry.py", line 190, in get_model
return self.get_app_config(app_label).get_model(model_name.lower())
File ".../django/apps/registry.py", line 138, in get_app_config
raise LookupError("No installed app with label '%s'." % app_label)
LookupError: No installed app with label 'auth'.
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 ".../django/core/management/__init__.py", line 385, in
execute_from_command_line
utility.execute()
File ".../django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File ".../django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File ".../django/core/management/base.py", line 337, in execute
output = self.handle(*args, **options)
File ".../django/core/management/commands/migrate.py", line 160, in
handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File ".../django/db/migrations/executor.py", line 62, in migrate
self.apply_migration(migration, fake=fake)
File ".../django/db/migrations/executor.py", line 90, in apply_migration
if self.detect_soft_applied(migration):
File ".../django/db/migrations/executor.py", line 134, in
detect_soft_applied
apps = project_state.render()
File ".../django/db/migrations/state.py", line 89, in render
model=lookup_model,
ValueError: Lookup failed for model referenced by field
myapp.MyModel.modifier: auth.User
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23182>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Typo in the bug report: My actual code does import `User` correctly from
`django.contrib.auth.models`.
--
Ticket URL: <https://code.djangoproject.com/ticket/23182#comment:1>
Old description:
New description:
Django 1.7rc2 on SQLite and Python 3.4. I'm trying to use
`squashmigrations`. It broke, even with `--no-optimize`. The documentation
said to report bugs.
My app `myapp` has a model `MyModel` with a couple foreign keys to
`django.contrib.auth.User` (yes, `auth` is in my `INSTALLED_APPS`, despite
what the stack trace below says; notably everything was working fine
before squashing):
{{{#!python
from django.contrib.auth.models import User
Then when I ran
--
--
Ticket URL: <https://code.djangoproject.com/ticket/23182#comment:2>
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Could you try with the latest `stable/1.7.x`. Also a minimal project that
we could download with steps to reproduce would be really helpful.
--
Ticket URL: <https://code.djangoproject.com/ticket/23182#comment:3>
* status: new => closed
* resolution: => needsinfo
Comment:
Please reopen if you can provide additional details.
--
Ticket URL: <https://code.djangoproject.com/ticket/23182#comment:4>
Comment (by wkschwartz):
Sorry I haven't been very helpful -- completely slammed at work. For what
it's worth, I reran the migration with `stable/1.7.x` @ 67870137b and the
squash worked. I was unable to come up with a test case that wasn't my
whole project.
--
Ticket URL: <https://code.djangoproject.com/ticket/23182#comment:5>