1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #23337 -- Raised exception if squashed migration created circular dependency.

This commit is contained in:
Ben Cail 2024-11-19 16:18:48 -05:00
parent 9543c605c3
commit 626afb6f13

View File

@ -6,6 +6,7 @@ from django.conf import settings
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.core.management.utils import run_formatters from django.core.management.utils import run_formatters
from django.db import DEFAULT_DB_ALIAS, connections, migrations from django.db import DEFAULT_DB_ALIAS, connections, migrations
from django.db.migrations.exceptions import CircularDependencyError
from django.db.migrations.loader import AmbiguityError, MigrationLoader from django.db.migrations.loader import AmbiguityError, MigrationLoader
from django.db.migrations.migration import SwappableTuple from django.db.migrations.migration import SwappableTuple
from django.db.migrations.optimizer import MigrationOptimizer from django.db.migrations.optimizer import MigrationOptimizer
@ -252,6 +253,14 @@ class Command(BaseCommand):
) )
) )
try:
MigrationLoader(connections[DEFAULT_DB_ALIAS])
except CircularDependencyError as e:
os.remove(writer.path)
raise CommandError(
f"Squashed migration would create a circular dependency: {e}"
)
def find_migration(self, loader, app_label, name): def find_migration(self, loader, app_label, name):
try: try:
return loader.get_migration_by_prefix(app_label, name) return loader.get_migration_by_prefix(app_label, name)