Fixed #27004 -- Made migrations consistency check ignore unapplied squashed migrations.

This commit is contained in:
Jarek Glowacki 2016-08-05 09:37:42 +10:00 committed by Tim Graham
parent 42f9d65107
commit d117567c7d
8 changed files with 61 additions and 0 deletions

View File

@ -280,6 +280,11 @@ class MigrationLoader(object):
continue continue
for parent in self.graph.node_map[migration].parents: for parent in self.graph.node_map[migration].parents:
if parent not in applied: if parent not in applied:
# Skip unapplied squashed migrations that have all of their
# `replaces` applied.
if parent in self.replacements:
if all(m in applied for m in self.replacements[parent].replaces):
continue
raise InconsistentMigrationHistory( raise InconsistentMigrationHistory(
"Migration {}.{} is applied before its dependency {}.{}".format( "Migration {}.{} is applied before its dependency {}.{}".format(
migration[0], migration[1], parent[0], parent[1], migration[0], migration[1], parent[0], parent[1],

View File

@ -29,3 +29,7 @@ Bugfixes
* Fixed the ``isnull`` lookup on a ``ForeignKey`` with its ``to_field`` * Fixed the ``isnull`` lookup on a ``ForeignKey`` with its ``to_field``
pointing to a ``CharField`` (:ticket:`26983`). pointing to a ``CharField`` (:ticket:`26983`).
* Prevented the ``migrate`` command from raising
``InconsistentMigrationHistory`` in the presence of unapplied squashed
migrations (:ticket:`27004`).

View File

@ -381,6 +381,23 @@ class LoaderTests(TestCase):
with self.assertRaisesMessage(InconsistentMigrationHistory, msg): with self.assertRaisesMessage(InconsistentMigrationHistory, msg):
loader.check_consistent_history(connection) loader.check_consistent_history(connection)
@override_settings(
MIGRATION_MODULES={'migrations': 'migrations.test_migrations_squashed_extra'},
INSTALLED_APPS=['migrations'],
)
def test_check_consistent_history_squashed(self):
"""
MigrationLoader.check_consistent_history() should ignore unapplied
squashed migrations that have all of their `replaces` applied.
"""
loader = MigrationLoader(connection=None)
recorder = MigrationRecorder(connection)
recorder.record_applied('migrations', '0001_initial')
recorder.record_applied('migrations', '0002_second')
loader.check_consistent_history(connection)
recorder.record_applied('migrations', '0003_third')
loader.check_consistent_history(connection)
@override_settings(MIGRATION_MODULES={ @override_settings(MIGRATION_MODULES={
"app1": "migrations.test_migrations_squashed_ref_squashed.app1", "app1": "migrations.test_migrations_squashed_ref_squashed.app1",
"app2": "migrations.test_migrations_squashed_ref_squashed.app2", "app2": "migrations.test_migrations_squashed_ref_squashed.app2",

View File

@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
pass

View File

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
replaces = [
("migrations", "0001_initial"),
("migrations", "0002_second"),
]

View File

@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("migrations", "0001_initial")]

View File

@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("migrations", "0002_second")]