diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2014-03-06 13:22:42 -0800 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2014-03-06 13:22:42 -0800 |
| commit | e46e15e5a17c1c42d01a343e7044d2d21588493d (patch) | |
| tree | 300d30d77dfae068320848104dd3bc84f4ac47be /django | |
| parent | 8ce3ea687cfae0bc47fcf023cb1f523dae4664ef (diff) | |
Fixed #22204: Bad circular-dep-breaking if more than one per run
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/migrations/autodetector.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py index db5c5e34e9..ec65d29321 100644 --- a/django/db/migrations/autodetector.py +++ b/django/db/migrations/autodetector.py @@ -94,9 +94,14 @@ class MigrationAutodetector(object): # Phase 2 is progressively adding pending models, splitting up into two # migrations if required. pending_new_fks = [] + added_phase_2 = set() while pending_add: # Is there one we can add that has all dependencies satisfied? - satisfied = [(m, rf) for m, rf in pending_add.items() if all((al, mn) not in pending_add for f, al, mn in rf)] + satisfied = [ + (m, rf) + for m, rf in pending_add.items() + if all((al, mn) not in pending_add for f, al, mn in rf) + ] if satisfied: (app_label, model_name), related_fields = sorted(satisfied)[0] model_state = self.to_state.models[app_label, model_name] @@ -107,7 +112,10 @@ class MigrationAutodetector(object): fields=model_state.fields, options=model_state.options, bases=model_state.bases, - ) + ), + # If it's already been added in phase 2 put it in a new + # migration for safety. + new=any((al, mn) in added_phase_2 for f, al, mn in related_fields), ) for field_name, other_app_label, other_model_name in related_fields: # If it depends on a swappable something, add a dynamic depend'cy @@ -117,6 +125,7 @@ class MigrationAutodetector(object): elif app_label != other_app_label: self.add_dependency(app_label, other_app_label) del pending_add[app_label, model_name] + added_phase_2.add((app_label, model_name)) # Ah well, we'll need to split one. Pick deterministically. else: (app_label, model_name), related_fields = sorted(pending_add.items())[0] @@ -342,6 +351,7 @@ class MigrationAutodetector(object): else: new_name = "%04i_%s" % (next_number, self.suggest_name(migration.operations)) name_map[(app_label, migration.name)] = (app_label, new_name) + next_number += 1 migration.name = new_name # Now fix dependencies for app_label, migrations in changes.items(): |
