Commits

Michael Manfre  committed eb3f4c5

Only drop CHECK and FOREIGN KEY constraints during sql_flush.

  • Participants
  • Parent commits 87a51fc

Comments (0)

Files changed (1)

File 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