-1
#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?

  • 2
    As the error message says: you cannot truncate a table that is being referenced by another. You need to use `DELETE` or drop the FK, truncate and re-create the FK. –  Apr 05 '14 at 06:57

1 Answers1

1

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;

From truncate foreign key constrained table

Community
  • 1
  • 1
user3470953
  • 11,025
  • 2
  • 17
  • 18