【问题排查记录】Field 'id' doesn't have a default value;


错误信息:

org.springframework.dao.DataIntegrityViolationException: StatementCallback; SQL [delete from table_a where union_id = 123456789;]; Field 'id' doesn't have a default value; nested exception is java.sql.BatchUpdateException: Field 'id' doesn't have a default value
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:249)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:407)
    at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:557)

出现错误的场景:

使用jdbctemplate向数据库批量更新时,报如上错误

解决思路:

1、首先排查,insert的语句中,是否包含自增列。

我的问题在于,从数据库中直接导出sql,没有勾选包含自增列,且数据多,未仔细检查,id未设置值,出现的问题。

2、不是手误的问题,就需要修改mysql校验列的条件了,即网上通用的修改方法


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM