是否可以在MySQL中暂时禁用约束?
我有两个Django模型,每个模型都有一个外键。由于ForeignKey约束,删除模型实例将返回错误:
cursor.execute("DELETE FROM myapp_item WHERE n = %s", n)
transaction.commit_unless_managed() #a foreign key constraint fails here
cursor.execute("DELETE FROM myapp_style WHERE n = %s", n)
transaction.commit_unless_managed()
是否可以暂时禁用约束并仍然删除?
ON DELETE SET NULL
怎么办?那将完成类似的事情,而您不必打开和关闭按键检查。