Column cannot be null
Error 1048 (SQLSTATE 23000) is raised when an INSERT or UPDATE attempts to set a NOT NULL column to NULL, and strict SQL mode is enabled. In non-strict mode, MariaDB may substitute the column's implicit default value and produce a warning instead of an error.
- 1Inserting a row without providing a value for a NOT NULL column that has no DEFAULT
- 2Explicitly passing NULL for a NOT NULL column
- 3Bulk loading data (LOAD DATA INFILE) where some rows have missing values for NOT NULL columns
An INSERT omits a required NOT NULL column with no DEFAULT.
CREATE TABLE orders ( id INT PRIMARY KEY AUTO_INCREMENT, customer_id INT NOT NULL, amount DECIMAL(10,2) NOT NULL ); INSERT INTO orders (customer_id) VALUES (42); -- amount is NULL
expected output
ERROR 1048 (23000): Column 'amount' cannot be null
Fix 1
Provide a value for every NOT NULL column
WHEN Always.
INSERT INTO orders (customer_id, amount) VALUES (42, 99.99);
Why this works
Explicitly providing all NOT NULL column values in the INSERT column list satisfies the constraint check before the row is written to the storage engine.
Fix 2
Add a DEFAULT value to the column
WHEN When a sensible default exists.
ALTER TABLE orders MODIFY amount DECIMAL(10,2) NOT NULL DEFAULT 0.00; INSERT INTO orders (customer_id) VALUES (42); -- amount defaults to 0.00
Why this works
When a DEFAULT is defined and the column is omitted from the INSERT, the server substitutes the default value before constraint validation.
✕ Disable strict mode to make the error a warning
In non-strict mode, MariaDB silently substitutes a zero/empty default, creating logically incorrect data (e.g., zero-amount orders) that is harder to detect.
Strict mode (STRICT_TRANS_TABLES) is enabled by default. Changing sql_mode to non-strict will downgrade this error to a warning.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev