douhui0975 2017-02-16 09:26 采纳率: 100%
浏览 233
已采纳

省略非默认字段时,在MariaDb上插入失败

Table Structure:

CREATE TABLE `setup_int` (
    `key` VARCHAR(50) NOT NULL,
    `val` INT(11) NOT NULL,
    PRIMARY KEY (`key`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB

As you can see the fields are NOT NULL-Fields and have no default value.

We updated to MariaDB 10.1.21 and have the following issue now: The following query fails without any error message!

INSERT INTO `setup_int` (`key`) VALUES ('test');

The reason seems to be the missing default value.

  • If I add an default value to the table, the insert is successfull.
  • If I change the NOT NULL to NULL, the insert is successfull.
  • IF I do it on MariaDB 10.1.20, the insert is successfull.
  • If I do the insert with both fields the insert is successfull.

This works:

INSERT INTO `setup_int` (`key`,`val`) VALUES ('test',0);

The question is: What can I do (some setting, or something else) to make mariadb 10.1.21 to handle this situation like before. I cannot alter all tables right now and i cannot downgrade right now.

The main issue is that the query executed by PHP returns true although the insert failed!

  • 写回答

2条回答 默认 最新

  • doris20141022 2017-02-16 09:32
    关注

    Take a look here: https://stackoverflow.com/a/2503938/1973205

    And then you can set the variables like this: https://mariadb.com/kb/en/mariadb/sql-mode/

    As a pure logic fact, it's correct that the query fails.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配