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条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效