Commits

Andrew Godwin committed 4c06786

Fix #252: Problems with capitalised constraints in alter_column

  • Participants
  • Parent commits f5fde6d

Comments (0)

Files changed (2)

File south/db/generic.py

         if self.has_check_constraints:
             check_constraints = self._constraints_affecting_columns(table_name, [name], "CHECK")
             for constraint in check_constraints:
-                self.execute(self.delete_check_sql % {'table':table_name, 'constraint': constraint})
+                self.execute(self.delete_check_sql % {'table': qn(table_name), 'constraint': qn(constraint)})
 
         # First, change the type
         params = {

File south/tests/db.py

             self.fail("Could insert non-unique pair.")
         db.delete_unique("test_unique", ["spam", "eggs", "ham_id"])
     
+    def test_capitalised_constraints(self):
+        """
+        Under PostgreSQL at least, capitalised constrains must be quoted.
+        """
+        db.start_transaction()
+        try:
+            db.create_table("test_capconst", [
+                ('SOMECOL', models.PositiveIntegerField(primary_key=True)),
+            ])
+            # Alter it so it's not got the check constraint
+            db.alter_column("test_capconst", "SOMECOL", models.IntegerField())
+        finally:
+            db.rollback_transaction()
+    
     def test_add_unique_fk(self):
         """
         Test adding a ForeignKey with unique=True or a OneToOneField