使用mybatis-plus时候报错Error updating database. Cause: java.sql.SQLException: Field 'subject_parent_id' doesn't have a default value

使用mybatis-plus添加课程时候报错

如图:

使用mybatis-plus时候报错Error updating database. Cause: java.sql.SQLException: Field 'subject_parent_id' doesn't have a default value_第1张图片

 

错误代码如图:

org.springframework.dao.DataIntegrityViolationException: 
### Error updating database.  Cause: java.sql.SQLException: Field 'subject_parent_id' doesn't have a default value
### The error may involve com.atguigu.eduservice.mapper.EduCourseMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO edu_course  ( id, teacher_id, subject_id,  title, price, lesson_num, cover,      gmt_create, gmt_modified )  VALUES  ( ?, ?, ?,  ?, ?, ?, ?,      ?, ? )
### Cause: java.sql.SQLException: Field 'subject_parent_id' doesn't have a default value
; Field 'subject_parent_id' doesn't have a default value; nested exception is java.sql.SQLException: Field 'subject_parent_id' doesn't have a default value
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:247)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
    at com.sun.proxy.$Proxy86.insert(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)

由于使用mybatis-plus代码生成器, 不能设置自增id, 所有不能用自增去解决

后来我发现把 'subject_parent_id' 非空√去掉就好了

使用mybatis-plus时候报错Error updating database. Cause: java.sql.SQLException: Field 'subject_parent_id' doesn't have a default value_第2张图片

 

添加成功, 如图:

 使用mybatis-plus时候报错Error updating database. Cause: java.sql.SQLException: Field 'subject_parent_id' doesn't have a default value_第3张图片

 

数据库中添加了两条信息(课程描述信息-表), 如图:

使用mybatis-plus时候报错Error updating database. Cause: java.sql.SQLException: Field 'subject_parent_id' doesn't have a default value_第4张图片

并且与课程中的id值是一样的(课程基本信息-表), 所有没有问题

 

 

 课程基本信息表与课程描述信息表中的id值相同, 这样添加课程基本信息的接口就完成了

你可能感兴趣的:(使用mybatis-plus时候报错Error updating database. Cause: java.sql.SQLException: Field 'subject_parent_id' doesn't have a default value)