3241
MySQLWARNINGNotableData IntegrityHIGH confidence
NULL value inserted into NOT NULL column
Production Risk
Medium — silent data corruption when default values are silently substituted.
How to reproduce
trigger — this will error
trigger — this will error
SET sql_mode=''; INSERT INTO t1 (not_null_col) VALUES (NULL);
expected output
Warning 3241: Column 'not_null_col' cannot be null.
Fix 1
Enable strict mode
Enable strict mode
SET sql_mode='STRICT_TRANS_TABLES'; INSERT INTO t1 (not_null_col) VALUES (NULL);
Why this works
Strict mode converts the warning to an error, forcing the application to fix the data.
Fix 2
Provide a default value
Provide a default value
INSERT INTO t1 (not_null_col) VALUES (COALESCE(@val, ''));
Why this works
COALESCE ensures a non-NULL fallback is always supplied.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 3241 ER_WARN_NULL_TO_NOTNULL
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev