java.sql.SQLIntegrityConstraintViolationException: Duplicate entry ‘2147483647‘ for key ‘PRIMARY‘
今天使用mybatis开发,在向manager表中添加数据时,遇到了这样的问题:
SQL: insert into manager (
name, mobile, franchiseeId, userId,roleCategory, status,createTime, updateTime
) values (?, ?,?, ?,?, ?,?, ?)
Cause:
java.sql.SQLIntegrityConstraintViolationException:
Duplicate entry '2147483647' for key 'PRIMARY';
这触发了主键唯一性的问题。
解决思路:
- 查询数据库中是否存有
id=2147483647
的记录,发现存有这条记录 既然存有
id = 2147483647
的记录,但为什么会出现如此大的id呢?- 查询这个id的上条记录的
id=400
,但manager表是自动增加的,因而,这条记录应该是id = 401
- 通过上面的分析,只能是MySQL的配置问题,有可能是
auto Increment = 2147483647
,于是,去查看manager表的配置
果然是配置的问题,可能其他研发人员误操作,修改autoi increment的值,于是,把该值修改为401,auto increment ,实际上是随着表中的id的改变而自动改变的。**
- 查询这个id的上条记录的
还没有评论,来说两句吧...