TRUNCATE a table that has FK constraints applied on it (
TRUNCATE is not the same as
To work around this, use either of these solutions. Both present risks of damaging the data integrity.
- Remove constraints
- Delete manually the rows that now have references to nowhere
- Create constraints
Option 2: suggested by user447951 in their answer
SET FOREIGN_KEY_CHECKS = 0; TRUNCATE table $table_name; SET FOREIGN_KEY_CHECKS = 1;