Mysql – disabling and enabling foreign key checks

Recently I was working on a project in which I have to truncate tables in database. But due to foreign key constraints MySQL was throwing errors.
So the solution I found was to disable Foreign Key constraints temporarily delete all data and then again enable the foreign keys.

Disable foreign key checks.

SET FOREIGN_KEY_CHECKS=0;

Enable foreign key checks.

SET FOREIGN_KEY_CHECKS=1;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.