#22563: Migration of admin.LogEntry.user fails. ---------------------------------+---------------------------------------- Reporter: efrinut@… | Owner: andrewgodwin Type: Bug | Status: new Component: Migrations | Version: 1.7-beta-2 Severity: Release blocker | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 ---------------------------------+---------------------------------------- Changes (by dekkers):
* cc: jeroen@… (added) * status: closed => new * resolution: fixed => Comment: Reopening the ticket as it is not completely fixed yet. I run into the same problem as berto. I tested the latest commit in the stable/1.7.x branch (9d0ebceb324ebb13b6d859153f95b2ef0c7c326b). To reproduce, create the following models.py: {{{#!python from django.db import models from django.contrib.auth.models import AbstractUser class MyModel(models.Model): pass class MyUser(AbstractUser): ref = models.ForeignKey('MyModel') }}} Change the user model to MyUser: {{{#!python AUTH_USER_MODEL = 'myapp.MyUser' }}} Run makemigrations, you can see that the migration for MyUser is created second: {{{ Migrations for 'myapp': 0001_initial.py: - Create model MyModel 0002_myuser.py: - Create model MyUser }}} And migrating fails: {{{ Operations to perform: Synchronize unmigrated apps: admin, contenttypes, auth, sessions Apply all migrations: myapp Synchronizing apps without migrations: Creating tables... Installing custom SQL... Installing indexes... Running migrations: Applying myapp.0001_initial...Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/home/jeroen/github/django/django/core/management/__init__.py", line 427, in execute_from_command_line utility.execute() File "/home/jeroen/github/django/django/core/management/__init__.py", line 419, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/jeroen/github/django/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__) File "/home/jeroen/github/django/django/core/management/base.py", line 337, in execute output = self.handle(*args, **options) File "/home/jeroen/github/django/django/core/management/commands/migrate.py", line 146, in handle executor.migrate(targets, plan, fake=options.get("fake", False)) File "/home/jeroen/github/django/django/db/migrations/executor.py", line 62, in migrate self.apply_migration(migration, fake=fake) File "/home/jeroen/github/django/django/db/migrations/executor.py", line 90, in apply_migration if self.detect_soft_applied(migration): File "/home/jeroen/github/django/django/db/migrations/executor.py", line 134, in detect_soft_applied apps = project_state.render() File "/home/jeroen/github/django/django/db/migrations/state.py", line 86, in render model=lookup_model, ValueError: Lookup failed for model referenced by field admin.LogEntry.user: myapp.MyUser }}} Simply swapping the migrations as berto suggested won't work for this case because it can't create MyUser when MyModel doesn't exist yet. A workaround is to first create MyUser without ForeignKey and then create MyModel and add the ForeignKey. -- Ticket URL: <https://code.djangoproject.com/ticket/22563#comment:26> 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/075.741bfa6115f9e81dbaaee0448208bd50%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.