LMSouq
database Open

How can I temporarily disable a foreign key constraint in MySQL?

JU
jul
1 month ago
3 views
Problem Description
Is it possible to temporarily disable constraints in MySQL? I have two Django models, each with a foreign key to the other one. Deleting instances of a model returns an error because of the foreign key constraint: 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() Is it possible to temporarily disable constraints and delete anyway?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base