我有一个包含很多字段的现有表,其中一些没有默认值,比如bellow。
在我的实体类中,我只想声明一些字段。
当我尝试插入新行时,我收到错误Field 'hours_work' doesn't have a default value
。
+------------------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+---------------+------+-----+---------+----------------+
| ...
| hours_work | text | NO | | NULL | |
| locations | text | NO | | NULL | |
| ...
然后,我将sql_mode
设置为''
mysql> set @@sql_mode='';
Query OK, 0 rows affected (0.00 sec)
所以我可以逐行插入,但不能使用我的应用程序
mysql> insert into MyTable (column1) values ('test value');
Query OK, 1 row affected, 84 warnings (0.00 sec)
我尝试在网址连接中设置sql_mode
,就像我在某些帖子中看到的那样,但是无法正常工作
application.yml
main:
datasource:
url: jdbc:mysql://localhost/my_database?sessionVariables=sql_mode=''
我感谢任何建议!
答案 0 :(得分:1)
根据下面的Sébastien解释,我能够修复它将jdbcCompliantTruncation=false
添加到MySQL URL连接。
塞巴斯蒂安,
驱动程序需要启用STRICT_TRANS_TABLES模式才能强制执行JDBC 遵守截断检查。
如果您不能将STRICT_TRANS_TABLES用作sql_mode的一部分,那么 你必须通过添加禁用截断检查 “jdbcCompliantTruncation = false”作为URL配置参数。
根据塞巴斯蒂安的说法,https://bugs.mysql.com/bug.php?id=23371
现在,URL连接看起来像
main:
datasource:
url: jdbc:mysql://localhost/edirectory_domain?jdbcCompliantTruncation=false&sessionVariables=sql_mode=''