Disable temporary a foreign key constraint in MySQL
Disable temporary a foreign key constraint in MySQL
Were you in the situation of having a mysql table and wanted to delete some records from it, but you were not allowed due to the constraints of that table? Don’t worry, me too. Or if you use foreign keys in your database tables, you’ll probably have problems on migrating data from one database to another. This is how you temporary disable all constraing keys from a mysql table. First step:
1 |
SET FOREIGN_KEY_CHECKS=0; |
Then make shure you put it back as it was before.
1 |
SET FOREIGN_KEY_CHECKS=1; |
What is a foreign key
From wikipedia: In the context of relational databases, a foreign key is a field (or collection of fields) in one table that uniquely identifies a row of another table. In other words, a foreign key is a column or a combination of columns that is used to establish and enforce a link between two tables.