Anonymous avatar Anonymous committed 401d26c

Fix #126: unique_together not working in dry run

Comments (0)

Files changed (3)

south/db/generic.py

         """
         Gets the names of the constraints affecting the given columns.
         """
+        
+        if self.dry_run:
+            raise ValueError("Cannot get constraints for columns during a dry run.")
+        
         columns = set(columns)
         
         if type == "CHECK":
         if not isinstance(columns, (list, tuple)):
             columns = [columns]
         
+        # Dry runs mean we can't do anything.
+        if self.dry_run:
+            return
+        
         constraints = list(self._constraints_affecting_columns(table_name, columns))
         if not constraints:
             raise ValueError("Cannot find a UNIQUE constraint on table %s, columns %r" % (table_name, columns))
 
     def delete_foreign_key(self, table_name, column):
         "Drop a foreign key constraint"
+        if self.dry_run:
+            return # We can't look at the DB to get the constraints
         constraints = list(self._constraints_affecting_columns(table_name, [column], "FOREIGN KEY"))
         if not constraints:
             raise ValueError("Cannot find a FOREIGN KEY constraint on table %s, column %s" % (table_name, column))

south/db/mysql.py

         """
         Gets the names of the constraints affecting the given columns.
         """
+        
+        if self.dry_run:
+            raise ValueError("Cannot get constraints for columns during a dry run.")
+        
         columns = set(columns)
         db_name = settings.DATABASE_NAME
         # First, load all constraint->col mappings for this table.

south/tests/db.py

         ])
         # Add a constraint
         db.create_unique("test_unique", ["spam"])
+        # Shouldn't do anything during dry-run
+        db.dry_run = True
+        db.delete_unique("test_unique", ["spam"])
+        db.dry_run = False
         db.delete_unique("test_unique", ["spam"])
         db.create_unique("test_unique", ["spam"])
         db.start_transaction()
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.