Cannot Truncate A Table Referenced In A Foreign Key Constraint

[Solved] Cannot Truncate A Table Referenced In A Foreign Key Constraint | Sql - Code Explorer | yomemimo.com
Question : cannot truncate a table referenced in a foreign key constraint

Answered by : amjadkhanroot

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE table $table_name;
SET FOREIGN_KEY_CHECKS = 1;

Source : https://stackoverflow.com/questions/5452760/how-to-truncate-a-foreign-key-constrained-table | Last Update : Wed, 21 Oct 20

Question : Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint

Answered by : lokesh-ramchandani

As the error says, you can not truncate tables referenced by foreign keys.
Delete should work though...
DB::table('some_table')->delete();

Source : | Last Update : Mon, 07 Dec 20

Question : how to force truncate a table in mysql

Answered by : nutty-newt-c8zxvbhgqxz1

DELETE FROM mytest.instance;
ALTER TABLE mytest.instance AUTO_INCREMENT = 1;

Source : | Last Update : Mon, 28 Dec 20

Answers related to cannot truncate a table referenced in a foreign key constraint

Code Explorer Popular Question For Sql