Sorted conflicting migrations by names.
This commit is contained in:
parent
52a0a03671
commit
04e4f80c1f
|
@ -317,7 +317,7 @@ class MigrationLoader:
|
||||||
if app_label in seen_apps:
|
if app_label in seen_apps:
|
||||||
conflicting_apps.add(app_label)
|
conflicting_apps.add(app_label)
|
||||||
seen_apps.setdefault(app_label, set()).add(migration_name)
|
seen_apps.setdefault(app_label, set()).add(migration_name)
|
||||||
return {app_label: seen_apps[app_label] for app_label in conflicting_apps}
|
return {app_label: sorted(seen_apps[app_label]) for app_label in conflicting_apps}
|
||||||
|
|
||||||
def project_state(self, nodes=None, at_end=True):
|
def project_state(self, nodes=None, at_end=True):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -247,7 +247,13 @@ class MigrateTests(MigrationTestBase):
|
||||||
"""
|
"""
|
||||||
migrate exits if it detects a conflict.
|
migrate exits if it detects a conflict.
|
||||||
"""
|
"""
|
||||||
with self.assertRaisesMessage(CommandError, "Conflicting migrations detected"):
|
msg = (
|
||||||
|
"Conflicting migrations detected; multiple leaf nodes in the "
|
||||||
|
"migration graph: (0002_conflicting_second, 0002_second in "
|
||||||
|
"migrations).\n"
|
||||||
|
"To fix them run 'python manage.py makemigrations --merge'"
|
||||||
|
)
|
||||||
|
with self.assertRaisesMessage(CommandError, msg):
|
||||||
call_command("migrate", "migrations")
|
call_command("migrate", "migrations")
|
||||||
|
|
||||||
@override_settings(MIGRATION_MODULES={
|
@override_settings(MIGRATION_MODULES={
|
||||||
|
@ -1066,16 +1072,13 @@ class MakeMigrationsTests(MigrationTestBase):
|
||||||
with self.temporary_migration_module(module="migrations.test_migrations_conflict"):
|
with self.temporary_migration_module(module="migrations.test_migrations_conflict"):
|
||||||
with self.assertRaises(CommandError) as context:
|
with self.assertRaises(CommandError) as context:
|
||||||
call_command("makemigrations")
|
call_command("makemigrations")
|
||||||
exception_message = str(context.exception)
|
self.assertEqual(
|
||||||
self.assertIn(
|
str(context.exception),
|
||||||
'Conflicting migrations detected; multiple leaf nodes '
|
"Conflicting migrations detected; multiple leaf nodes in the "
|
||||||
'in the migration graph:',
|
"migration graph: (0002_conflicting_second, 0002_second in "
|
||||||
exception_message
|
"migrations).\n"
|
||||||
|
"To fix them run 'python manage.py makemigrations --merge'"
|
||||||
)
|
)
|
||||||
self.assertIn('0002_second', exception_message)
|
|
||||||
self.assertIn('0002_conflicting_second', exception_message)
|
|
||||||
self.assertIn('in migrations', exception_message)
|
|
||||||
self.assertIn("To fix them run 'python manage.py makemigrations --merge'", exception_message)
|
|
||||||
|
|
||||||
def test_makemigrations_merge_no_conflict(self):
|
def test_makemigrations_merge_no_conflict(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1488,20 +1491,16 @@ class MakeMigrationsTests(MigrationTestBase):
|
||||||
"makemigrations", "conflicting_app_with_dependencies",
|
"makemigrations", "conflicting_app_with_dependencies",
|
||||||
merge=True, interactive=True, stdout=out
|
merge=True, interactive=True, stdout=out
|
||||||
)
|
)
|
||||||
val = out.getvalue().lower()
|
self.assertEqual(
|
||||||
self.assertIn('merging conflicting_app_with_dependencies\n', val)
|
out.getvalue().lower(),
|
||||||
self.assertIn(
|
'merging conflicting_app_with_dependencies\n'
|
||||||
' branch 0002_conflicting_second\n'
|
' branch 0002_conflicting_second\n'
|
||||||
' - create model something\n',
|
' - create model something\n'
|
||||||
val
|
|
||||||
)
|
|
||||||
self.assertIn(
|
|
||||||
' branch 0002_second\n'
|
' branch 0002_second\n'
|
||||||
' - delete model tribble\n'
|
' - delete model tribble\n'
|
||||||
' - remove field silly_field from author\n'
|
' - remove field silly_field from author\n'
|
||||||
' - add field rating to author\n'
|
' - add field rating to author\n'
|
||||||
' - create model book\n',
|
' - create model book\n'
|
||||||
val
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_makemigrations_with_custom_name(self):
|
def test_makemigrations_with_custom_name(self):
|
||||||
|
|
Loading…
Reference in New Issue