首页 > 数据库 >MySQL清空表提示Cannot truncate a table referenced in a foreign key constraint

MySQL清空表提示Cannot truncate a table referenced in a foreign key constraint

时间:2022-11-16 17:56:16浏览次数:45  
标签:referenced truncate constraint Cannot key MySQL table

MySQL清空表提示Cannot truncate a table referenced in a foreign key constraint

在MySQL执行truncate table xxx时, 出现了这个报错[Err] 1701 -Cannot truncate a table referenced in a foreign key constraint..

意思是 无法截断外键约束中引用的表

解决办法

  • mysql中运行 SET FOREIGN_KEY_CHECKS=0,删除外键约束
  • 之后执行 SET FOREIGN_KEY_CHECKS=1,启动外键约束
  • 在重新truncate table xxx;清空就可以了

标签:referenced,truncate,constraint,Cannot,key,MySQL,table
From: https://www.cnblogs.com/yyx0417/p/16896821.html

相关文章