省略非默认字段时,在MariaDb上插入失败(Insert on MariaDb fails when ommitting non

编程入门 行业动态 更新时间:2024-10-26 14:37:28
省略非默认字段时,在MariaDb上插入失败(Insert on MariaDb fails when ommitting non-default fields)

表结构:

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

如您所见,字段为NOT NULL -Fields且没有默认值。

我们更新到MariaDB 10.1.21并立即出现以下问题:以下查询失败,没有任何错误消息!

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

原因似乎是缺少默认值。

如果我向表中添加默认值,则插入成功。 如果我将NOT NULL更改为NULL ,则插入成功。 如果我在MariaDB 10.1.20上执行此操作,则插入是成功的。 如果我使用两个字段执行插入,则插入成功。

这有效:

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

问题是:我可以做些什么(一些设置或其他东西)来使mariadb 10.1.21像以前一样处理这种情况。 我现在无法改变所有表格,现在我无法降级。

主要问题是PHP执行的查询返回true尽管插入失败!

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!

最满意答案

看看这里: https : //stackoverflow.com/a/2503938/1973205

然后你可以像这样设置变量: https : //mariadb.com/kb/en/mariadb/sql-mode/

作为一个纯粹的逻辑事实,查询失败是正确的。

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.

更多推荐

本文发布于:2023-08-05 05:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1427638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   MariaDb   Insert   fails   ommitting

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!