java - 外键约束失败 该怎么解决

 高粱_ 发布于 2022-10-25 11:24

WARNING]
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException:

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (lgip.tb_intention, CONSTRAINT fk_intention_user FOREIGN KEY (firm_id) REFERENCES tb_user (id))

The error may involve com.nstc.lgip.idao.TbIntentionMapper.insert-Inline

The error occurred while setting parameters

SQL: insert into tb_intention (id, firm_id, industry_type ) values (?, ?, ? )

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (lgip.tb_intention, CONSTRAINT fk_intention_user FOREIGN KEY (firm_id) REFERENCES tb_user (id))

; SQL []; Cannot add or update a child row: a foreign key constraint fails (lgip.tb_intention, CONSTRAINT fk_intention_user FOREIGN KEY (firm_id) REFERENCES tb_user (id)); nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (lgip.tb_intention, CONSTRAINT fk_intention_user FOREIGN KEY (firm_id) REFERENCES tb_user (id))

2 个回答
  • 外键表对主键表做左链接查询到有部分id没有在主键表中存在 之后是删是留改自己决定咯

    2022-11-12 01:41 回答
  • 你插入的 firm_id在tb_user表中没有对应的id。。。。。。。

    2022-11-12 01:41 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有