Ticket #26180: ticket26180-temp-fix.diff

File ticket26180-temp-fix.diff, 2.2 KB (added by Akshesh Doshi, 3 years ago)
  • django/db/migrations/autodetector.py

    diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py
    index ae88a90..d102c19 100644
    a b class MigrationAutodetector(object): 
    351351        # Optimize migrations
    352352        for app_label, migrations in self.migrations.items():
    353353            for migration in migrations:
    354                 migration.operations = MigrationOptimizer().optimize(migration.operations, app_label=app_label)
     354                opt_operations = MigrationOptimizer().optimize(migration.operations, app_label=app_label)
     355                # Preserve the order if no optmization took place
     356                if len(opt_operations) < len(migration.operations):
     357                    migration.operations = opt_operations
    355358
    356359    def check_dependency(self, operation, dependency):
    357360        """
  • tests/migrations/test_autodetector.py

    diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
    index 68c4e85..0370f52 100644
    a b class AutodetectorTests(TestCase): 
    12331233        )
    12341234        # Right number/type of migrations?
    12351235        self.assertNumberMigrations(changes, "otherapp", 1)
    1236         self.assertOperationTypes(changes, "otherapp", 0, ["RemoveField", "AlterUniqueTogether", "AlterIndexTogether"])
    1237         self.assertOperationAttributes(changes, "otherapp", 0, 0, model_name="book", name="newfield")
    1238         self.assertOperationAttributes(changes, "otherapp", 0, 1, name="book", unique_together={("author", "title")})
    1239         self.assertOperationAttributes(changes, "otherapp", 0, 2, name="book", index_together={("author", "title")})
     1236        self.assertOperationTypes(changes, "otherapp", 0, ["AlterUniqueTogether", "AlterIndexTogether", "RemoveField"])
     1237        self.assertOperationAttributes(changes, "otherapp", 0, 0, name="book", unique_together={("author", "title")})
     1238        self.assertOperationAttributes(changes, "otherapp", 0, 1, name="book", index_together={("author", "title")})
     1239        self.assertOperationAttributes(changes, "otherapp", 0, 2, model_name="book", name="newfield")
    12401240
    12411241    def test_rename_field_and_foo_together(self):
    12421242        """
Back to Top