How can I solve the "1701, 'Cannot truncate a table referenced in a foreign key constraint" issue in MySQL when trying to truncate a table?
-
I have two tables: CREATE TABLE IF NOT EXISTS `submissions` ( `submission_id` INT(11) NOT NULL AUTO_INCREMENT) CREATE TABLE IF NOT EXISTS `assessments` ( `assessment_id` INT NOT NULL AUTO_INCREMENT , `submission_id` INT NOT NULL , CONSTRAINT `submission` FOREIGN KEY (`submission_id` ) REFERENCES `submissions` (`submission_id` ) ON DELETE NO ACTION ON UPDATE NO ACTION) When I try to execute TRUNCATE submissions;, I get the error: "_mysql_exceptions.OperationalError: (1701, 'Cannot truncate a table referenced in a foreign key constraint (`assessments`, CONSTRAINT `submission` FOREIGN KEY (`submission_id`) REFERENCES `submissions` (`submission_id`))')" How can I circumvent it?
-
Answer:
You can disable the foreign key check before truncating the table: SET FOREIGN_KEY_CHECKS=0; TRUNCATE submissions; SET FOREIGN_KEY_CHECKS=1; Beware that this might break the integrity of the database.
Franck Dernoncourt at Quora Visit the source
Related Q & A:
- How can I communicate Raspberry Pi and Arduino (in both ways) using a 10-15m distance wires?Best solution by Arduino
- How can I echo characters before and after a string?Best solution by stackoverflow.com
- How can I send an http request at a specific time?Best solution by Stack Overflow
- How can I burn a .rmvb file onto a DVD for viewing on a regular DVD player?Best solution by Yahoo! Answers
- How can I print wirelessly from a laptop to a printer without a router?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.