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

如图:

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

 

错误代码如图:

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

 

添加成功, 如图:

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

 

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

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

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

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

 

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

相关文章:

  • 2021-05-29
  • 2022-02-28
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-27
  • 2021-11-17
  • 2021-08-09
  • 2022-12-23
  • 2021-04-02
  • 2021-06-28
  • 2021-04-13
相关资源
相似解决方案