闲来无事运行我以前写的代码时,报错MySQLIntegrityConstraintViolationException: #23000.
一. 异常原因
插入主键时,表中已有相同的主键,所以报错.插入的新数据,与表的主键唯一约束产生了冲突
就是新数据的主键在表中已经存在了.
二. 解决方法
1.更换插入的主键数据
2.把主键设置为自动递增,插入数据时不插入主键.
墨衍会员
·
AI 创作全网分发
墨衍智能分发
本文由作者通过墨衍一键同步至各平台
1分发平台
5.1k累计阅读
5.2k平均单平台
已同步平台
CSDN
微信公众号
微博
知乎
掘金
百家号
博客园
抖音
小红书
你的文章也可以这样分发
墨衍会员 ¥399起/年,写一次发全网
我也要 →
码龄5年
闲来无事运行我以前写的代码时,报错MySQLIntegrityConstraintViolationException: #23000.
插入主键时,表中已有相同的主键,所以报错.插入的新数据,与表的主键唯一约束产生了冲突
就是新数据的主键在表中已经存在了.
1.更换插入的主键数据
2.把主键设置为自动递增,插入数据时不插入主键.
当前文章被以下社区和专栏收录:
java.sql.SQLIntegrityConstraintViolationException: #23000
java.sql.SQLIntegrityConstraintViolationException: #23000**异常信息****异常原因****解决方法** 异常信息 ### Cause: java.sql.SQLIntegrityConstraintViolationException: #23000 ; #23000; nested exception is java.sql.SQLIntegrityConstraintViolationException: #23000] with root c
mybatis插入数据报错:#23000,#22001,1054
Cause: java.sql.SQLIntegrityConstraintViolationException: #23000 我的这个错是由于主键冲突了导致
Mysql出现问题:ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constrain fail解决方案
Mysql出现问题:ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constrain fail解决方案
MySQLIntegrityConstraintViolationException异常处理
一、异常现象 操作数据库的时候报出异常MySQLIntegrityConstraintViolationException 错误异常:MySQLIntegrityConstraintViolationException的意思是违反了数据库的完整性约束,在表中建立了唯一索引 Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:Duplicate entry '0' for k
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0' for key 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.
MySql常见报错
mysql常见报错
MySQLIntegrityConstraintViolationException: Column 'roleId' in field list is ambiguous
MySQLIntegrityConstraintViolationException <select id="getRoleByUserAccount" resultType="sun.lab.domain.Role" parameterType="String"> select roleId, r.roleName from role r, user u ...
MySQLIntegrityConstraintViolationException: Column ‘DEAL_FLAG‘ cannot be null
MySQL更新语句错误导致非空约束冲突。问题SQL中将字段分隔符错用为AND(正确应为逗号),导致deal_flag未被赋值而违反非空约束。修正方案:将UPDATE语句中的"AND"改为逗号分隔字段,并确保参数非空。典型错误示例:UPDATE table SET field1=1 AND field2=?(错误),正确应为UPDATE table SET field1=1, field2=?。该错误同时提醒需注意:参数校验、避免全表更新、修改后重新编译等问题。关键记忆点:MySQL多字段
报错解决:MySQLIntegrityConstraintViolationException: Duplicate entry ‘0‘ for key ‘PRI
而且数据库是使用的雪花算法生成的id,也说明一个问题,在字段里配置id策略的优先高于在配置文件里配置的。注意:此时MySQL数据库的表的id字段是没有设置自增的。但是我的配置文件里是配置里Auto形式的。主要的原因是我的数据库里已经有id为0的数据了,然后我的id默认值也是0,所以就重复了。我尝试在Navicat中将id的默认值去掉,发现去不掉…然后就报了上面这个错,报错很明显,其实就是id重复了。但是重启Navicat后,再设置为0就可以了。注意:直接在Navicat里面加是不生效的!
MySQLIntegrityConstraintViolationException: Column 'ID' in where clause is ambiguous ;
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'ID' in where clause is ambiguous ; SQL []; Column 'ID' in where clause is ambiguous; nested exception is com
MySQL插入数据出错及解决方案
项目中对MySQL插入数据的时候,出现错误信息,查阅网上相关文章后解决,记录之,下次供参考。
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate ent
错误原因: 代码中遍历插入数据,报错主键重复,mybatis在默认事务中,一个事物执行多条插入语句,mybatis没办法获取插入第一条的主键,我的代码中添加了selectKey标签,所以删除select标签即可解决不能批量插入问题 <insert id="insertSelective" parameterType="com.reada.pojo.ReadaUserTag" > ...
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'area' in where clause is ambiguous 翻译就是:where子句中的“area”列是不明确的 是SQL语句关联表查询的时候,因为多张表中都有area字段,所以才会报错说查询条件不知道是查询哪站表里的字段。只要在条件area前加上查询表的别名就行。 例如:s.area = #{areaId} ...
springMVC报错:### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
原因之一是处理中间表时将其中的一个栏位设置为主键了,取消掉这个主键且不需设置为自增长
mysql 外键冲突_MySQL外键约束冲突异常:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:...
异常内容Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`book`.`t_order`, CON...
采坑笔记--
1,问题描述: 确保数据的唯一性,使用sql 语句 on duplicate unique update ,在mybaits中的mapper文件中拼接sql,出现第二次执行,报 Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0' for ...
30个CSS选择器(updating)
1、*:通用选择器 针对初学者来说,我们还是从简单的开始学起,首先我们来认识下通用选择器,然后再逐步深入学习其它高级的选择器,假如我们想让文档中的每个元素都显示成红色,我们可以这么做: * {color:red;} 通用选择器,可以匹配页面所有的元素。 许多开发者可能会用这个技巧如下代码所示让元素居中,在开发测试阶段固然是好的,但是我不建议这么做,因为这样做会给浏览器增加很大的负担。 * { ...
**控制台报错: Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your
#解决办法 在XXXmapper.xml文件中找出控制台指定行数,然后删除“}”该大括号
MySQL生产事故一例
背景 分析 解决方案 参考
665
220
1905
1026
554

被折叠的 条评论
为什么被折叠?



