Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#22823 closed Bug (fixed)

Migrate fails when an unmigrated app has a FK to a migrated app

Reported by: Ben Davis Owned by: Andrew Godwin
Component: Migrations Version: dev
Severity: Release blocker Keywords:
Cc: django@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This ticket is a spin-off from #22563, as it's not clear yet whether or not the issues are related.

Assuming you have 3 apps A, B, and C, such that:

  • A has migrations
  • B has a migration we want to apply
  • C has no migrations, but has an FK to A

When we try to migrate "B", an exception occurs because the "B" was not included in the ProjectState that is used to detect soft-applied migrations.

Change History (8)

comment:1 by Tim Graham, 11 years ago

Duplicate of #22660?

comment:2 by Ben Davis, 11 years ago

I think this is a different issue, as it has a different exception. It's more likely related to #22563, but that hasn't been determined yet.

comment:4 by Ben Davis, 11 years ago

This is the exception raised by the test mentioned above:

Testing against Django installed in '/home/ben/.local/src/django/django'
Creating test database for alias 'default'...
Creating test database for alias 'other'...
.....................E.
======================================================================
ERROR: test_regression_22823_unmigrated_fk_to_migrated_model (migrations.test_commands.MigrateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ben/.local/src/django/django/test/utils.py", line 316, in inner
    return test_func(*args, **kwargs)
  File "/home/ben/.local/src/django/django/test/utils.py", line 216, in inner
    return test_func(*args, **kwargs)
  File "/home/ben/.local/src/django/tests/migrations/test_commands.py", line 126, in test_regression_22823_unmigrated_fk_to_migrated_model
    call_command("migrate", "migrated_unapplied_app", stdout=stdout)
  File "/home/ben/.local/src/django/django/core/management/__init__.py", line 115, in call_command
    return klass.execute(*args, **defaults)
  File "/home/ben/.local/src/django/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/home/ben/.local/src/django/django/core/management/commands/migrate.py", line 146, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/home/ben/.local/src/django/django/db/migrations/executor.py", line 62, in migrate
    self.apply_migration(migration, fake=fake)
  File "/home/ben/.local/src/django/django/db/migrations/executor.py", line 90, in apply_migration
    if self.detect_soft_applied(migration):
  File "/home/ben/.local/src/django/django/db/migrations/executor.py", line 134, in detect_soft_applied
    apps = project_state.render()
  File "/home/ben/.local/src/django/django/db/migrations/state.py", line 102, in render
    model=lookup_model,
ValueError: Lookup failed for model referenced by field unmigrated_app.SillyModel.silly_tribble: migrations.Tribble

comment:5 by Andrew Godwin, 11 years ago

Owner: changed from nobody to Andrew Godwin
Status: newassigned

I'm looking into this; I think it may actually be the same underlying issue as #22823 after all (that Django doesn't expect FKs from outside the migrations hierarchy into it)

comment:6 by no, 11 years ago

Cc: django@… added

comment:7 by Andrew Godwin <andrew@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 7b17350a1bfa527358e722baf962a5f9cfb838ea:

Fixed #22823 (and partly #22563) - FKs from unmigrated apps breaking state.

Thanks to bendavis78 for the test and diagnostic work.

comment:8 by Andrew Godwin <andrew@…>, 11 years ago

In 961c9d6c6b1975fba8eb1492288e0fc49652c43d:

[1.7.x] Fixed #22823 (and partly #22563) - FKs from unmigrated apps breaking state.

Thanks to bendavis78 for the test and diagnostic work.

Note: See TracTickets for help on using tickets.
Back to Top