如何解决Cause: java.sql.SQLException: Field ‘id‘ doesn‘t have a default value

When doing the product upload function, I reported Cause: java.sql.SQLException: Field'id' doesn't have a default value error (the main error is as follows). The query is because the ID self-increase is set in mapper.xml. But the database is not caused by self-growth

Solutions:

Step 1: Check if your id is of int type, because I set the string type myself, so I can’t find the auto-increment box when using Navicat

public class FoodEntity {
    /**
     * 商品ID
     */
    @TableId
    private String id; // 这里设置为String 照样会出错
    //自动增长的类型是int
    private int id
    

Step 2: Open Navicat Premium, and click Design Table for the table to be operated

Step 3: Check the automatic growth

Restart the project to achieve the corresponding operation

 

Guess you like

Origin blog.csdn.net/xgysimida/article/details/108200269