Cannot add or update a child row: a foreign key constraint fails的解决方法

当遇到'Cannot add or update a child row: a foreign key constraint fails'错误时,通常是因为外键关联的字段不是主键,或者字段中存在重复值导致。解决方法是确保外键关联的字段具有唯一性,避免映射错误。详细解决方案可在相关博客文章中找到。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 ERROR 4388 --- [io-10086-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: 
### Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`crm`.`cst_customer`, CONSTRAINT `cstsc_KY_base` FOREIGN KEY (`cust_source`) REFERENCES `base_dict` (`dict_type_code`) ON DELETE CASCADE ON UPDATE CASCADE)

解决方法:因为外键关联的字段不是主键,或者是外键关联的字段不具有唯一性,就是是外键关联的字段里有重复的数值,不具备唯一性,导致映射出错。

详细讲解可以参考文章:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值