LEATH
与其禁用约束,不如将其永久修改为ON DELETE SET NULL。这将完成类似的事情,您将不必打开和关闭键检查。就像这样:ALTER TABLE tablename1 DROP FOREIGN KEY fk_name1;
//get rid of current constraintsALTER TABLE tablename2 DROP FOREIGN KEY fk_name2;ALTER TABLE tablename1
ADD FOREIGN KEY (table2_id)
REFERENCES table2(id)
ON DELETE SET NULL //add back constraintALTER TABLE tablename2
ADD FOREIGN KEY (table1_id)
REFERENCES table1(id)
ON DELETE SET NULL //add back other constraint读一读(http:/dev.mysql.com/doc/reflman/5.5/en/ALTER-table.html)和这个(http:/dev.mysql.com/doc/reflman/5.5/en/cre-table-foreign-keys.html).