Error updating database. Cause: java.sql.BatchUpdateException: Field 'id' doesn't have a default value

时间:2021-02-08 04:59:51

异常信息

### Error updating database.  Cause: java.sql.BatchUpdateException: Field 'id' doesn't have a default value
Query is: INSERT INTO
`test`.`order`
( `order`.`code`,
`order`.`create_date`,
`order`.`status`,
)
VALUES ( ?, ?,

原因

数据库表设计时候id没有加自动增长

mybatis添加后执行了查询id 而报错

<selectKey resultType="long"
keyProperty="id"
order="AFTER">
SELECT
LAST_INSERT_ID()
</selectKey>

解决方法

把mysql数据库的id设为自增列