完整的错误描述如下:

ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constrai
nt (`mytest`.`social_account`, CONSTRAINT `fk_user_account` FOREIGN KEY (`user_i
d`) REFERENCES `mytest`.`user` (`id`))

 

要清空的表中的user表中id字段是其他表中的外键约束

 

谷歌了一下,解决之:

set foreign_key_checks = 0;

truncate table1;
truncate table2;
...;
truncate tableN;

set foreign_key_checks = 1;

 

请注意:请确保可以清空的情况下再使用。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2022-03-04
  • 2022-12-23
  • 2021-11-28
  • 2021-12-10
  • 2022-12-23
猜你喜欢
  • 2021-11-17
  • 2021-06-13
  • 2021-09-16
  • 2022-12-23
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案