#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 migrationsB
has a migration we want to applyC
has no migrations, but has an FK toA
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 , 10 years ago
comment:2 by , 10 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:3 by , 10 years ago
Here is a failing test case for this issue:
https://github.com/bendavis78/django/commit/b8e0a17ed3fcd1b51a6dd84f4a9dd963572f5eca
comment:4 by , 10 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 , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
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 , 10 years ago
Cc: | added |
---|
comment:7 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Duplicate of #22660?