mirror of
https://github.com/django/django.git
synced 2024-12-23 09:36:06 +00:00
Fixed #33246 -- Made squashmigrations raise CommandError when squashed_name already exists.
This commit is contained in:
parent
c3e0dfe4cc
commit
9e6d631697
@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
@ -184,6 +186,10 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
# Write out the new migration file
|
# Write out the new migration file
|
||||||
writer = MigrationWriter(new_migration, include_header)
|
writer = MigrationWriter(new_migration, include_header)
|
||||||
|
if os.path.exists(writer.path):
|
||||||
|
raise CommandError(
|
||||||
|
f'Migration {new_migration.name} already exists. Use a different name.'
|
||||||
|
)
|
||||||
with open(writer.path, "w", encoding='utf-8') as fh:
|
with open(writer.path, "w", encoding='utf-8') as fh:
|
||||||
fh.write(writer.as_string())
|
fh.write(writer.as_string())
|
||||||
|
|
||||||
|
@ -2082,6 +2082,15 @@ class SquashMigrationsTests(MigrationTestBase):
|
|||||||
squashed_migration_file = os.path.join(migration_dir, '0001_%s.py' % squashed_name)
|
squashed_migration_file = os.path.join(migration_dir, '0001_%s.py' % squashed_name)
|
||||||
self.assertTrue(os.path.exists(squashed_migration_file))
|
self.assertTrue(os.path.exists(squashed_migration_file))
|
||||||
|
|
||||||
|
def test_squashed_name_exists(self):
|
||||||
|
msg = 'Migration 0001_initial already exists. Use a different name.'
|
||||||
|
with self.temporary_migration_module(module='migrations.test_migrations'):
|
||||||
|
with self.assertRaisesMessage(CommandError, msg):
|
||||||
|
call_command(
|
||||||
|
'squashmigrations', 'migrations', '0001', '0002',
|
||||||
|
squashed_name='initial', interactive=False, verbosity=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AppLabelErrorTests(TestCase):
|
class AppLabelErrorTests(TestCase):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user