From 39f83765e12b0e5d260b7939fc3fe281d879b279 Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Mon, 8 Mar 2021 13:36:14 +0000 Subject: [PATCH] Refs #32528 -- Simplified MigrationAutodetector._sort_migrations(). --- django/db/migrations/autodetector.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py index 1cb3a19f641..5a5f5a14fb0 100644 --- a/django/db/migrations/autodetector.py +++ b/django/db/migrations/autodetector.py @@ -391,10 +391,9 @@ class MigrationAutodetector: # Resolve intra-app dependencies to handle circular # references involving a swappable model. dep = self._resolve_dependency(dep)[0] - if dep[0] == app_label: - for op2 in ops: - if self.check_dependency(op2, dep): - ts.add(op, op2) + if dep[0] != app_label: + continue + ts.add(op, *(x for x in ops if self.check_dependency(x, dep))) self.generated_operations[app_label] = list(ts.static_order()) def _optimize_migrations(self):