Cannot truncate a table referenced in a foreign key constraint

 
mysql 中使用truncate 清空数据表时,报错:
 
Cannot truncate a table referenced in a foreign key constraint (`51ask`.`aw_role_user`, CONSTRAINT `role_user_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `51ask`.`aw_roles` (`id`))


解决办法:
 
关闭外键约束->清空表->启动外键约束。
 
具体操作:
 
mysql>SET FOREIGN_KEY_CHECKS = 0;

mysql>TRUNCATE table;

mysql>SET FOREIGN_KEY_CHECKS = 1;

 

0 个评论

要回复文章请先登录注册