在利用 mybatis 對數據將進行插入數據的時候,出現了如下錯誤:
1 org.springframework.dao.DataIntegrityViolationException: 2 ### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'third_party_id' cannot be null 3 ### The error may involve com.miaoshaproject.dao.UserDOMapper.insert-Inline 4 ### The error occurred while setting parameters 5 ### SQL: insert into user_info (id, name, gender, age, telephone, register_mode, third_party_id) values (?, ?, ?, ?, ?, ?, ?) 6 ### Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'third_party_id' cannot be null 7 ; Column 'third_party_id' cannot be null; nested exception is java.sql.SQLIntegrityConstraintViolationException: Column 'third_party_id' cannot be null
最后檢查了代碼,發現是在操作數據庫的部分,最后定位到數據庫字段的設計:在使用 insertSelective 方法的時候,如果數據庫字段設置了非空,但是沒有給默認值,會出現上面的錯誤。
又是因為細節問題導致的報錯問題,實屬不該。