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

发布时间 2023-08-20 21:28:39作者: 哩个啷个波

报错内容:

 是因为实体类文件中设置主键自增的类型不对导致的,建议再温习一下逐渐自增的类型以及使用方式

我自己的实体类里面设置的IdType为auto,但是主键id是char类型的,还不是int数值类型,所以无法设置为自增

 这里需要换成

IdType.ID_WORKER_STR
   @ApiModelProperty(value = "讲师ID")
    @TableId(value = "id", type = IdType.ID_WORKER_STR)
    private String id;
这样子就可以了,如果你的主键id类型是int等数值类型,就设置为auto,数据库设置一下id自增就可以了.