异常信息

1
2
3
4
5
6
7
8
org.springframework.dao.DataIntegrityViolationException:
### Error updating database. Cause: java.sql.SQLException: Field 'id' doesn't have a default value
### The error may exist in file [xxx.xml]
### The error may involve xxxMapper.insert-Inline
### The error occurred while setting parameters
### SQL: insert into xxx create_time ) values ( ?, ?, ?, ?, ? )
### Cause: java.sql.SQLException: Field 'id' doesn't have a default value
; Field 'id' doesn't have a default value; nested exception is java.sql.SQLException: Field 'id' doesn't have a default value

解决方案

原因:插入时没有指定 id,且数据库没有自增主键。
处理:在 xml 中添加 <if test="id != null">id,</if> 手动设置 id;或者在数据库中设置自增。

评论