【問題排查記錄】Field 'id' doesn't have a default value;

錯誤信息:java

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)

出現錯誤的場景:mysql

使用jdbctemplate向數據庫批量更新時,報如上錯誤spring

解決思路:sql

一、首先排查,insert的語句中,是否包含自增列。數據庫

個人問題在於,從數據庫中直接導出sql,沒有勾選包含自增列,且數據多,未仔細檢查,id未設置值,出現的問題。spa

二、不是手誤的問題,就須要修改mysql校驗列的條件了,即網上通用的修改方法code

相關文章
相關標籤/搜索