#23182: squashmigrations having trouble with auth.User foreign key ------------------------------+------------------------------------------ Reporter: wkschwartz@… | Owner: nobody Type: Bug | Status: new Component: Migrations | Version: 1.7-rc-2 Severity: Normal | Keywords: migrations, squashmigrations Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ------------------------------+------------------------------------------ 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 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. -- 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.8b140cab7dc3b52020f9013a56fee444%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.