squashmigrations having trouble with auth.User foreign key
|Reported by:||wkschwartz@…||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Description (last modified by timo)
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):
from django.contrib.auth.models 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
(venv) $ ./manage.py squashmigrations myapp 0018
Then when I ran
(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, lookup_model) 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
Change History (4)
comment:3 Changed 18 months ago by timo
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:4 Changed 18 months ago by timgraham
- Resolution set to needsinfo
- Status changed from new to closed