Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow squashing of squashed migrations

  • Loading branch information...
commit c7bf4c27a0b82c6d33622c648a6016b68c9f44d9 1 parent 106b019
Andrew Godwin authored
15  django/core/management/commands/squashmigrations.py
@@ -37,9 +37,9 @@ def handle(self, app_label=None, migration_name=None, **options):
37 37
         try:
38 38
             migration = executor.loader.get_migration_by_prefix(app_label, migration_name)
39 39
         except AmbiguityError:
40  
-            raise CommandError("More than one migration matches '%s' in app '%s'. Please be more specific." % (app_label, migration_name))
  40
+            raise CommandError("More than one migration matches '%s' in app '%s'. Please be more specific." % (migration_name, app_label))
41 41
         except KeyError:
42  
-            raise CommandError("Cannot find a migration matching '%s' from app '%s'." % (app_label, migration_name))
  42
+            raise CommandError("Cannot find a migration matching '%s' from app '%s'." % (migration_name, app_label))
43 43
 
44 44
         # Work out the list of predecessor migrations
45 45
         migrations_to_squash = [
@@ -83,11 +83,20 @@ def handle(self, app_label=None, migration_name=None, **options):
83 83
             else:
84 84
                 self.stdout.write("  Optimized from %s operations to %s operations." % (len(operations), len(new_operations)))
85 85
 
  86
+        # Work out the value of replaces (any squashed ones we're re-squashing)
  87
+        # need to feed their replaces into ours
  88
+        replaces = []
  89
+        for migration in migrations_to_squash:
  90
+            if migration.replaces:
  91
+                replaces.extend(migration.replaces)
  92
+            else:
  93
+                replaces.append((migration.app_label, migration.name))
  94
+
86 95
         # Make a new migration with those operations
87 96
         subclass = type("Migration", (migrations.Migration, ), {
88 97
             "dependencies": [],
89 98
             "operations": new_operations,
90  
-            "replaces": [(m.app_label, m.name) for m in migrations_to_squash],
  99
+            "replaces": replaces,
91 100
         })
92 101
         new_migration = subclass("0001_squashed_%s" % migration.name, app_label)
93 102
 

0 notes on commit c7bf4c2

Please sign in to comment.
Something went wrong with that request. Please try again.