Commits

Mikhail Denisenko committed 4c2ee0f

bugfix constraints should be deleted before indexes otherwise we can get error: An explicit DROP INDEX is not allowed on index

Comments (0)

Files changed (2)

south/db/sql_server/pyodbc.py

     def delete_column(self, table_name, name):
         q_table_name, q_name = (self.quote_name(table_name), self.quote_name(name))
 
+        # Zap the constraints
+        for const in self._find_constraints_for_column(table_name,name):
+            params = {'table_name':q_table_name, 'constraint_name': const}
+            sql = self.drop_constraint_string % params
+            self.execute(sql, [])
+
         # Zap the indexes
         for ind in self._find_indexes_for_column(table_name,name):
             params = {'table_name':q_table_name, 'index_name': ind}
             sql = self.drop_index_string % params
             self.execute(sql, [])
 
-        # Zap the constraints
-        for const in self._find_constraints_for_column(table_name,name):
-            params = {'table_name':q_table_name, 'constraint_name': const}
-            sql = self.drop_constraint_string % params
-            self.execute(sql, [])
-
         # Zap default if exists
         drop_default = self.drop_column_default_sql(table_name, name)
         if drop_default:

south/tests/db.py

         db.delete_column("test_addc", "add1")
         db.delete_table("test_addc")
 
+    def test_delete_columns(self):
+        """
+        Test deleting columns
+        """
+        db.create_table("test_delc", [
+            ('spam', models.BooleanField(default=False)),
+            ('eggs', models.IntegerField(db_index=True, unique=True)),
+        ])
+        db.delete_column("test_delc", "eggs")
+
     def test_add_nullbool_column(self):
         """
         Test adding NullBoolean columns
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.