summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorGeorgi Yanchev <georgi.yanchev@gmail.com>2025-01-20 09:12:09 +0100
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-01-22 10:56:30 +0100
commit64b1ac7292c72d3551b2ad70b2a78c8fe4af3249 (patch)
tree2d450bab4fef8e37e1466b4478ecad7a94396f23 /django/core
parent322785b08cf21f2b7a627caf459e73e6170dd602 (diff)
Fixed #24529 -- Allowed double squashing of migrations.
Co-authored-by: Raphael Gaschignard <raphael@rtpg.co>
Diffstat (limited to 'django/core')
-rw-r--r--django/core/management/commands/squashmigrations.py20
1 files changed, 3 insertions, 17 deletions
diff --git a/django/core/management/commands/squashmigrations.py b/django/core/management/commands/squashmigrations.py
index bb636116a5..9845b4d456 100644
--- a/django/core/management/commands/squashmigrations.py
+++ b/django/core/management/commands/squashmigrations.py
@@ -5,12 +5,11 @@ from django.apps import apps
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.core.management.utils import run_formatters
-from django.db import DEFAULT_DB_ALIAS, connections, migrations
+from django.db import migrations
from django.db.migrations.loader import AmbiguityError, MigrationLoader
from django.db.migrations.migration import SwappableTuple
from django.db.migrations.optimizer import MigrationOptimizer
from django.db.migrations.writer import MigrationWriter
-from django.utils.version import get_docs_version
class Command(BaseCommand):
@@ -75,7 +74,7 @@ class Command(BaseCommand):
raise CommandError(str(err))
# Load the current graph state, check the app and migration they asked
# for exists.
- loader = MigrationLoader(connections[DEFAULT_DB_ALIAS])
+ loader = MigrationLoader(None)
if app_label not in loader.migrated_apps:
raise CommandError(
"App '%s' does not have migrations (so squashmigrations on "
@@ -141,12 +140,6 @@ class Command(BaseCommand):
# as it may be 0002 depending on 0001
first_migration = True
for smigration in migrations_to_squash:
- if smigration.replaces:
- raise CommandError(
- "You cannot squash squashed migrations! Please transition it to a "
- "normal migration first: https://docs.djangoproject.com/en/%s/"
- "topics/migrations/#squashing-migrations" % get_docs_version()
- )
operations.extend(smigration.operations)
for dependency in smigration.dependencies:
if isinstance(dependency, SwappableTuple):
@@ -180,14 +173,7 @@ class Command(BaseCommand):
% (len(operations), len(new_operations))
)
- # Work out the value of replaces (any squashed ones we're re-squashing)
- # need to feed their replaces into ours
- replaces = []
- for migration in migrations_to_squash:
- if migration.replaces:
- replaces.extend(migration.replaces)
- else:
- replaces.append((migration.app_label, migration.name))
+ replaces = [(m.app_label, m.name) for m in migrations_to_squash]
# Make a new migration with those operations
subclass = type(