Commits

Anonymous committed 401d26c

Fix #126: unique_together not working in dry run

  • Participants
  • Parent commits 5608187
  • Tags 0.5

Comments (0)

Files changed (3)

File 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))

File 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.

File 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()