首页 > 数据库 >mysql报错 a foreign key constraint fails(外键约束错误)

mysql报错 a foreign key constraint fails(外键约束错误)

时间:2022-09-19 16:26:25浏览次数:84  
标签:fails constraint 外键 约束 报错 key

报错信息如下:

(pymysql.err.IntegrityError) (1452, u'Cannot add or update a child row: a foreign key constraint fails

解决办法:

SET FOREIGN_KEY_CHECKS = 0; # 临时取消外键约束
SET FOREIGN_KEY_CHECKS = 1; # 开启外键约束

添加之前临时取消一下外键约束,添加好数据之后,再将外键约束改回来就可以啦!

标签:fails,constraint,外键,约束,报错,key
From: https://www.cnblogs.com/lemperor/p/16708034.html

相关文章