【問題排查記錄】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