You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

非严格模式下MariaDB无法插入空值问题求助

Troubleshooting NOT NULL Column Insertion Issues in MariaDB 10.1 (Debian 9)

Hey there, let's break down what's going on here and fix that insertion issue you're facing.

First, let's clarify the key differences between your old MySQL 5.6 setup and the new MariaDB 10.1 environment. Even though your sql_mode shows only NO_ENGINE_SUBSTITUTION, there's another critical setting in MariaDB that might be enforcing strict checks on NOT NULL columns—innodb_strict_mode.

Step 1: Verify the innodb_strict_mode setting

Run this query to check if it's enabled:

SHOW VARIABLES LIKE 'innodb_strict_mode';

If the value is ON, that's likely the culprit. Unlike MySQL 5.6, MariaDB enables innodb_strict_mode by default in many cases, and this setting overrides the non-strict sql_mode behavior for InnoDB tables. When it's on, inserting a NULL into a NOT NULL column (even without a default) will throw an error instead of falling back to an implicit default (like an empty string for text fields, or 0 for numeric fields).

Step 2: Test with a temporary fix

To confirm this is the issue, disable innodb_strict_mode for your current session first:

SET SESSION innodb_strict_mode = OFF;

Try inserting your data again—this should behave just like your old MySQL 5.6 environment did.

Step 3: Make the change permanent

If the temporary fix works, update your MariaDB configuration file (usually located at /etc/mysql/my.cnf or /etc/mysql/mariadb.conf.d/50-server.cnf on Debian 9) to add or modify this line:

innodb_strict_mode = OFF

Then restart the MariaDB service to apply the change system-wide:

sudo systemctl restart mariadb

Bonus: Check session-level sql_mode

Sometimes applications or database drivers override the global sql_mode when establishing a connection. Double-check your session-specific setting with:

SHOW SESSION VARIABLES LIKE 'sql_mode';

If this includes strict mode values (like STRICT_TRANS_TABLES or STRICT_ALL_TABLES), you'll need to adjust your application's connection settings to avoid overriding the global mode.

That should resolve the insertion error you're seeing. Let me know if you run into any issues while implementing this!


内容的提问来源于stack exchange,提问作者Romulo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:44:36