java.sql.SQLException: Field 'supplier_id' doesn't have a default value

前端 未结 6 1672
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 17:14

I got an error message from this:

 java.sql.SQLException: Field \'supplier_id\' doesn\'t have a default value
    at com.mysql.jdbc.SQLError.createSQLExcepti         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 18:12

    The error is self explanatory. Your column supplier_id does not have a default value. So during insertion, mysql cannot figure out what to insert in the column supplier_id. You can do either of the three things :-
    1. Add a default value to the column supplier_id Using -

    ALTER TABLE `xxx` ALTER `supplier_id` SET DEFAULT NULL
    


    2. Supply some value to the supplier_id column during insertion.
    3. Add an auto increment to the column and add a primary key to it using the code :-

    ALTER TABLE `xxx` CHANGE `supplier_id` `supplier_id` INT(10)AUTO_INCREMENT PRIMARY KEY;
    

提交回复
热议问题