完整的错误描述如下:
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;
请注意:请确保可以清空的情况下再使用。