[Solved] Cause: java.sql.SQLException: Field ‘id‘ doesn‘t have a default value

When doing the product upload function, we reported the error of cause: Java. SQL. Sqlexception: field ‘ID’ doesn’t have a default value (the main error is as follows). After query, it was caused by setting ID self growth in mapper.xml, but not in the database

Solutions:

Step 1: check whether my ID is int type, because I set string type, so I can’t find the self incrementing check box when using Navicat

public class FoodEntity {
    /**
     * Product ID
     */
    @TableId
    private String id; // set to String here, but it will still error out
    // The auto-grow type is int
    private int id
    

Step 2: open Navicat premium and click design table for the table to be operated

Step 3: check auto growth

Then restart the project to achieve the corresponding operation

Similar Posts: