1
0
mirror of https://github.com/django/django.git synced 2025-04-07 06:56:40 +00:00

Fixed #36184 -- Allowed migrating forward to squashed migrations.

This commit is contained in:
Jacob Walls 2025-03-30 08:18:18 -04:00 committed by Sarah Boyce
parent 12385b4fa7
commit a0fb35eb72
2 changed files with 19 additions and 9 deletions

View File

@ -37,18 +37,18 @@ class MigrationExecutor:
if migration in applied:
plan.append((self.loader.graph.nodes[migration], True))
applied.pop(migration)
# If the target is missing, it's likely a replaced migration.
# Reload the graph without replacements.
elif (
self.loader.replace_migrations
and target not in self.loader.graph.node_map
):
self.loader.replace_migrations = False
self.loader.build_graph()
return self.migration_plan(targets, clean_start=clean_start)
# If the migration is already applied, do backwards mode,
# otherwise do forwards mode.
elif target in applied:
# If the target is missing, it's likely a replaced migration.
# Reload the graph without replacements.
if (
self.loader.replace_migrations
and target not in self.loader.graph.node_map
):
self.loader.replace_migrations = False
self.loader.build_graph()
return self.migration_plan(targets, clean_start=clean_start)
# Don't migrate backwards all the way to the target node (that
# may roll back dependencies in other apps that don't need to
# be rolled back); instead roll back through target's immediate

View File

@ -1328,6 +1328,16 @@ class MigrateTests(MigrationTestBase):
# Unmigrate everything.
call_command("migrate", "migrations", "zero", verbosity=0)
@override_settings(
MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"}
)
def test_migrate_forward_to_squashed_migration(self):
try:
call_command("migrate", "migrations", "0001_initial", verbosity=0)
finally:
# Unmigrate everything.
call_command("migrate", "migrations", "zero", verbosity=0)
@override_settings(
MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"}
)