Opened 7 years ago

Closed 7 years ago

#28493 closed Bug (fixed)

Foreign keys break on migration if models are renamed in a different app

Reported by: Christopher Neugebauer Owned by: Jeremy Satterfield
Component: Migrations Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Christopher Neugebauer)

Steps to reproduce:

  1. Create app a, with a model called A. Run makemigrations a
  2. Create app b, with a model called B. Give B a ForeignKey to A. Run makemigrations b
  3. Rename model A to Aa. Run makemigrations a
  4. Run migrate

Expected behaviour:

The migration completes successfully

Actual behaviour:

Migration 0001 on b is run after migration 0002 on a, and the migration fails with the following error:

raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model u'a.A' cannot be resolved

Change History (6)

comment:1 by Christopher Neugebauer, 7 years ago

Description: modified (diff)

comment:2 by Christopher Neugebauer, 7 years ago

Component: UncategorizedMigrations

comment:3 by Christopher Neugebauer, 7 years ago

n.b. it is possible to make these migrations work by manually adding run_before, but it seems to me like this *should* be able to run automatically.

comment:4 by Jeremy Satterfield, 7 years ago

Has patch: set
Owner: changed from nobody to Jeremy Satterfield
Status: newassigned

This seems to me the exact reason for the dependencies list in migrations.

comment:5 by Chris Beaven, 7 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:6 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In 0891503f:

Fixed #28493 -- Made migrations autodetector find dependencies for model renaming.

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