Michael Manfre avatar Michael Manfre committed eb3f4c5

Only drop CHECK and FOREIGN KEY constraints during sql_flush.

Comments (0)

Files changed (1)

source/sqlserver_ado/operations.py

             elem.update(seq)
             seqs.append(elem)
 
-        cursor.execute("SELECT TABLE_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS")
+        cursor.execute("SELECT TABLE_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE IN ('CHECK', 'FOREIGN KEY')")
         fks = cursor.fetchall()
         
         sql_list = list()
 
         # Turn off constraints.
         sql_list.extend(['ALTER TABLE %s NOCHECK CONSTRAINT %s;' % (
-            qn(fk[0]), qn(fk[1])) for fk in fks])
+            qn(fk[0]), qn(fk[1])) for fk in fks if fk[0] != None and fk[1] != None])
 
         # Delete data from tables.
         sql_list.extend(['%s %s %s;' % (
 
         # Turn constraints back on.
         sql_list.extend(['ALTER TABLE %s CHECK CONSTRAINT %s;' % (
-            qn(fk[0]), qn(fk[1])) for fk in fks])
+            qn(fk[0]), qn(fk[1])) for fk in fks if fk[0] != None and fk[1] != None])
 
         return sql_list
 
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.