#1701 - Cannot truncate a table referenced in a foreign key constraint (`away_order_detail`, CONSTRAINT `away_order_detail_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `away_order_master` (`id`))
I am facing this problem can you give me any solution?
#1701 - Cannot truncate a table referenced in a foreign key constraint (`away_order_detail`, CONSTRAINT `away_order_detail_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `away_order_master` (`id`))
I am facing this problem can you give me any solution?
You cannot TRUNCATE a table that has FK constraints applied on it (truncate is not the same as delete).
To work around:
Option 1 which does not risk damage to data integrity:
Remove constraints Perform TRUNCATE Delete manually the rows that now have references to "nowhere" Create constraints
Option 2, which is bad practice, if you are OK risking damage to data integrity
SET FOREIGN_KEY_CHECKS=0; TRUNCATE table1; SET FOREIGN_KEY_CHECKS=1;