diff --git a/django/db/migrations/executor.py b/django/db/migrations/executor.py index eb738cf4571f..13afa5988f68 100644 --- a/django/db/migrations/executor.py +++ b/django/db/migrations/executor.py @@ -224,6 +224,9 @@ def _migrate_all_backwards(self, plan, full_plan, fake): # remaining applied migrations. last_unapplied_migration = plan[-1][0] state = states[last_unapplied_migration] + # Avoid mutating state with apps rendered as it's an expensive + # operation. + del state.apps for index, (migration, _) in enumerate(full_plan): if migration == last_unapplied_migration: for migration, _ in full_plan[index:]: