开发者社区> 问答> 正文

双向同步报主键冲突和唯一索引冲突,如何解决或跳过

因为主键冲突和唯一索引冲突导致挂起不能同步,不知如何解决

唯一索引冲突:

org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [insert into ysod.product_gd_detail(gd_id , ws_id , comp_number , pass_number , nopass_number , effect_pass , operator_id , work_hour , comp_date , owner_id , finish , station_id , real_pass_number , real_comp_number , id) values (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ?) on duplicate key update gd_id=values(gd_id) , ws_id=values(ws_id) , comp_number=values(comp_number) , pass_number=values(pass_number) , nopass_number=values(nopass_number) , effect_pass=values(effect_pass) , operator_id=values(operator_id) , work_hour=values(work_hour) , comp_date=values(comp_date) , owner_id=values(owner_id) , finish=values(finish) , station_id=values(station_id) , real_pass_number=values(real_pass_number) , real_comp_number=values(real_comp_number) , id=values(id)]; Duplicate entry '3466728-1198-49287' for key 'gd_id_2'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '3466728-1198-49287' for key 'gd_id_2'

主键冲突:

pid:15 nid:6 exception:setl:com.alibaba.otter.node.etl.load.exception.LoadException: java.util.concurrent.ExecutionException: com.alibaba.otter.node.etl.load.exception.LoadException: com.alibaba.otter.node.etl.load.exception.LoadException: com.alibaba.otter.node.etl.load.exception.LoadException: org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [update ysod.product_gd_detail set gd_id = ? , ws_id = ? , comp_number = ? , pass_number = ? , nopass_number = ? , effect_pass = ? , operator_id = ? , work_hour = ? , comp_date = ? , owner_id = ? , finish = ? , station_id = ? , real_pass_number = ? , real_comp_number = ? , id = ? where ( id = ? )]; Duplicate entry '29830031' for key 'PRIMARY'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '29830031' for key 'PRIMARY'

原提问者GitHub用户 zhuhuawu

展开
收起
大圣东游 2023-06-21 16:34:05 75 0
1 条回答
写回答
取消 提交回答
  • 如果涉及唯一键的变更,建议是先删除后插入的模式,否则针对多个唯一键的记录进行交换的时候会出错

    原回答者GitHub用户agapple

    2023-06-21 17:41:55
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载