MySQL “Field 'userId' doesn't have a default value”
程序员文章站
2022-03-22 08:42:20
...
意图通过程序往表中插入一条新的数据,执行SQL语句如下:
insert into t_table (parma1, parma2) values(value1, value2);
执行结果显示没有通过,异常则是 “Field ‘userId’ doesn’t have a default value”
{
"status": 500,
"err": "
### Error updating database. Cause: java.sql.SQLException: Field 'parma2' doesn't have a default value
### The error may involve com.XXMapper.insertSelective-Inline
### The error occurred while setting parameters
### SQL: insert into t_book ( parma1 ) values ( ? )
### Cause: java.sql.SQLException: Field 'parma2' doesn't have a default value
; ]; Field 'parma2' doesn't have a default value; nested exception is java.sql.SQLException: Field 'parma2' doesn't have a default value"
}
出发试着解决问题,不管是程序上还是直接百度
从异常信息的字面上,不外乎 “无设置默认值” 的问题,事实上真的是这样麽 ?
- 不是没有设置默认值的问题 [数值默认0,其他默认NULL]
- 非配置文件配置问题,因为在mysql7.0及以上找不到配置文件 “my.ini” 或者 “my_default.ini”
- 亦非SQL语句问题,越过程序直接执行一切OK
… 这才回过神来,异常信息中体现的SQL少了一个 parma2参数
- 不是 mapper.xml 脚本文件中的配置问题
- 非 controller.java 文件中参数配置问题
- 而是对象中 parma2 属性少了 set()函数,当然构造函数也不例外 - -!!
推荐阅读
-
MySQL之Field‘***’doesn’t have a default value错误解决办法
-
MySQL添加用户错误:ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value解决方法
-
Field 'id' doesn't have a default value错误解决方法
-
ERROR: Field 'PostId' doesn't have a default value Exception in thread "main" org.hibernate.exception.GenericJDBCException: coul
-
[MySQL] BLOB, TEXT, GEOMETRY or JSON column 'body' can't have a default value错误
-
thinkphp-General error: 1364 Field doesn't have a default v
-
MySQL添加用户错误:ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value解决方法
-
mysql创建用户报错ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
-
MySQL之Field‘***’doesn’t have a default value错误解决办法
-
MySQL之Field‘***’doesn’t have a default value错误解决办法_MySQL