Andrew Godwin avatar Andrew Godwin committed 99da2b5

Ensure correct ordering of unique deletion w.r.t. table deletion

Comments (0)

Files changed (2)

south/creator/actions.py

     the forwards() and backwards() method lists.
     """
     
+    prepend_forwards = False
+    prepend_backwards = False
+    
     def forwards_code(self):
         raise NotImplementedError
     
         raise NotImplementedError
     
     def add_forwards(self, forwards):
-        forwards.append(self.forwards_code())
+        if self.prepend_forwards:
+            forwards.insert(0, self.forwards_code())
+        else:
+            forwards.append(self.forwards_code())
     
     def add_backwards(self, backwards):
-        backwards.append(self.backwards_code())
+        if self.prepend_backwards:
+            backwards.insert(0, self.backwards_code())
+        else:
+            backwards.append(self.backwards_code())
     
     def console_line(self):
         "Returns the string to print on the console, e.g. ' + Added field foo'"
         # Removing unique constraint on '%(model_name)s', fields %(field_names)s
         db.delete_unique(%(table_name)r, %(fields)r)'''
     
+    prepend_backwards = True
+    
     def __init__(self, model, fields):
         self.model = model
         self.fields = fields
     Removes a unique constraint from a model. Takes a Model class and the field names.
     """
     
+    prepend_forwards = True
+    prepend_backwards = False
+    
     def console_line(self):
         "Returns the string to print on the console, e.g. ' + Added field foo'"
         return " - Deleted unique constraint for %s on %s.%s" % (

south/creator/changes.py

                 # We shouldn't delete it if it was managed=False
                 old_fields, old_meta, old_m2ms = self.split_model_def(self.old_orm[key], self.old_defs[key])
                 if old_meta.get("managed", "True") != "False":
-                    # Make sure we delete any M2Ms it had.
+                    # Alright, delete it.
+                    yield ("DeleteModel", {
+                        "model": self.old_orm[key], 
+                        "model_def": old_fields,
+                    })
+                    # Also make sure we delete any M2Ms it had.
                     for fieldname in old_m2ms:
                         # Only delete its stuff if it wasn't a through=.
                         field = self.old_orm[key + ":" + fieldname]
                                 "model": self.old_orm[key],
                                 "fields": [self.old_orm[key]._meta.get_field_by_name(x)[0] for x in fields],
                             })
-                    # Finally, delete it.
-                    yield ("DeleteModel", {
-                        "model": self.old_orm[key], 
-                        "model_def": old_fields,
-                    })
                 # We always add it in here so we ignore it later
                 deleted_models.add(key)
         
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.