Categories
Uncategorized

How to temporarily disable a foreign key constraint in MySQL?

To temporarily disable a foreign key constraint in MySQL, we set the FOREIGN_KEY_CHECKS environment variable.

To disable it, we run

SET FOREIGN_KEY_CHECKS=0;

to set FOREIGN_KEY_CHECKS to 0.

And then we enable it again by running

SET FOREIGN_KEY_CHECKS=1;