Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-12-01 · container image mysql:8.4
ERROR 1048 means the statement tries to store NULL in a column declared NOT NULL. Unlike ERROR 1364 (column left out), here a NULL value is actually given, either written directly or produced by a SELECT or subquery.
The message names the column. Korean and Japanese translations exist and are shown on each language page. Below are five causes verified on MySQL 8.4.
01The INSERT passes NULL for a NOT NULL column
email is NOT NULL and the INSERT gives NULL for it. This often happens when the application sends an empty value as NULL.
Setup
CREATE TABLE customers (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) NOT NULL, email VARCHAR(100) NOT NULL);Query OK, 0 rows affected (0.01 sec)INSERT INTO customers (name, email) VALUES ('Kim', NULL);ERROR 1048 (23000): Column 'email' cannot be nullSELECT column_name, is_nullable FROM information_schema.columns WHERE table_schema = 'lab_a' AND table_name = 'customers' ORDER BY ordinal_position;+-------------+-------------+
| COLUMN_NAME | IS_NULLABLE |
+-------------+-------------+
| id | NO |
| name | NO |
| email | NO |
+-------------+-------------+
3 rows in set (0.00 sec)information_schema.columns shows IS_NULLABLE = NO for every column. Give a real value: the INSERT with 'kim@example.com' succeeds.
INSERT INTO customers (name, email) VALUES ('Kim', 'kim@example.com');
SELECT * FROM customers;Query OK, 1 row affected (0.00 sec)
+----+------+-----------------+
| id | name | email |
+----+------+-----------------+
| 1 | Kim | kim@example.com |
+----+------+-----------------+
1 row in set (0.01 sec)02INSERT ... SELECT copies NULLs from the source
The import table has dept = NULL for 'Lee'. Copying into employees, where dept is NOT NULL, fails for the whole statement.
Setup
CREATE TABLE import_rows (id INT, name VARCHAR(50), dept VARCHAR(20));
INSERT INTO import_rows VALUES (1, 'Kim', 'Sales'), (2, 'Lee', NULL);
CREATE TABLE employees (id INT PRIMARY KEY, name VARCHAR(50) NOT NULL, dept VARCHAR(20) NOT NULL);Query OK, 0 rows affected (0.02 sec)
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
Query OK, 0 rows affected (0.01 sec)INSERT INTO employees (id, name, dept) SELECT id, name, dept FROM import_rows;ERROR 1048 (23000): Column 'dept' cannot be nullSELECT * FROM import_rows WHERE dept IS NULL;+------+------+------+
| id | name | dept |
+------+------+------+
| 2 | Lee | NULL |
+------+------+------+
1 row in set (0.00 sec)WHERE dept IS NULL finds the row. Replace the NULL while copying: COALESCE(dept, 'UNASSIGNED'). Both rows are inserted, 'Lee' with UNASSIGNED.
INSERT INTO employees (id, name, dept) SELECT id, name, COALESCE(dept, 'UNASSIGNED') FROM import_rows;
SELECT * FROM employees ORDER BY id;Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
+----+------+------------+
| id | name | dept |
+----+------+------------+
| 1 | Kim | Sales |
| 2 | Lee | UNASSIGNED |
+----+------+------------+
2 rows in set (0.00 sec)03An UPDATE subquery finds no row and returns NULL
SET price = (SELECT p.price FROM price_list p WHERE p.sku = oi.sku) returns NULL for sku B9, which is not in the price list. price is NOT NULL, so the UPDATE fails.
Setup
CREATE TABLE price_list (sku VARCHAR(10) PRIMARY KEY, price INT NOT NULL);
INSERT INTO price_list VALUES ('A1', 100);
CREATE TABLE order_items (id INT PRIMARY KEY, sku VARCHAR(10), price INT NOT NULL);
INSERT INTO order_items VALUES (1, 'A1', 0), (2, 'B9', 0);Query OK, 0 rows affected (0.01 sec)
Query OK, 1 row affected (0.01 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0UPDATE order_items oi SET price = (SELECT p.price FROM price_list p WHERE p.sku = oi.sku);ERROR 1048 (23000): Column 'price' cannot be nullSELECT oi.id, oi.sku, p.price FROM order_items oi LEFT JOIN price_list p ON p.sku = oi.sku ORDER BY oi.id;+----+------+-------+
| id | sku | price |
+----+------+-------+
| 1 | A1 | 100 |
| 2 | B9 | NULL |
+----+------+-------+
2 rows in set (0.00 sec)A LEFT JOIN shows B9 has no price (NULL). Update only rows that match with a JOIN: UPDATE order_items oi JOIN price_list p ON p.sku = oi.sku SET oi.price = p.price. Row 1 becomes 100 and B9 keeps 0.
UPDATE order_items oi JOIN price_list p ON p.sku = oi.sku SET oi.price = p.price;
SELECT * FROM order_items ORDER BY id;Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
+----+------+-------+
| id | sku | price |
+----+------+-------+
| 1 | A1 | 100 |
| 2 | B9 | 0 |
+----+------+-------+
2 rows in set (0.00 sec)04SUM() for a customer with no orders is NULL, not 0
The UPDATE writes each customer's order total into total_amount (NOT NULL). Customer 1 has orders, customer 2 has none. Over zero rows SUM() returns NULL, not 0, so customer 2's row raised 1048 and the whole UPDATE failed.
Setup
CREATE TABLE customers (id INT PRIMARY KEY, total_amount INT NOT NULL DEFAULT 0);
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT, amount INT);
INSERT INTO customers VALUES (1, 0), (2, 0);
INSERT INTO orders VALUES (1, 1, 100), (2, 1, 250);Query OK, 0 rows affected (0.02 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0UPDATE customers c
SET total_amount = (SELECT SUM(o.amount) FROM orders o WHERE o.customer_id = c.id);ERROR 1048 (23000): Column 'total_amount' cannot be nullSELECT c.id, (SELECT SUM(o.amount) FROM orders o WHERE o.customer_id = c.id) AS sum_amount
FROM customers c ORDER BY c.id;+------+------------+
| id | sum_amount |
+------+------------+
| 1 | 350 |
| 2 | NULL |
+------+------------+
2 rows in set (0.00 sec)Running the subquery alone gives 350 for customer 1 and NULL for customer 2. The customer without orders produces the NULL.
SELECT SUM(amount) AS sum_none, COALESCE(SUM(amount), 0) AS coalesced FROM orders WHERE customer_id = 2;+----------+-----------+
| sum_none | coalesced |
+----------+-----------+
| NULL | 0 |
+----------+-----------+
1 row in set (0.00 sec)With COALESCE(SUM(o.amount), 0) the UPDATE worked and customer 2 stayed at 0 (Rows matched: 2 Changed: 1). COUNT() returns 0 over no rows, but SUM, MAX, and AVG return NULL.
UPDATE customers c
SET total_amount = (SELECT COALESCE(SUM(o.amount), 0) FROM orders o WHERE o.customer_id = c.id);
SELECT * FROM customers ORDER BY id;Query OK, 1 row affected (0.01 sec)
Rows matched: 2 Changed: 1 Warnings: 0
+----+--------------+
| id | total_amount |
+----+--------------+
| 1 | 350 |
| 2 | 0 |
+----+--------------+
2 rows in set (0.00 sec)05A LEFT JOIN in INSERT ... SELECT finds no matching code
Staging rows were LEFT JOINed to the department code table to fill in the department name, but employee 2 had code D30, which is not in depts. A LEFT JOIN fills the right side with NULL when there is no match, so dept_name (NOT NULL) raised 1048, and employee 1 was not inserted either.
Setup
CREATE TABLE depts (code VARCHAR(10) PRIMARY KEY, name VARCHAR(30));
INSERT INTO depts VALUES ('D10', 'Sales'), ('D20', 'IT');
CREATE TABLE stg_emps (id INT, name VARCHAR(30), dept_code VARCHAR(10));
INSERT INTO stg_emps VALUES (1, 'Kim', 'D10'), (2, 'Lee', 'D30');
CREATE TABLE emps (id INT PRIMARY KEY, name VARCHAR(30), dept_name VARCHAR(30) NOT NULL);Query OK, 0 rows affected (0.01 sec)
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
Query OK, 0 rows affected (0.01 sec)
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
Query OK, 0 rows affected (0.01 sec)INSERT INTO emps (id, name, dept_name)
SELECT s.id, s.name, d.name
FROM stg_emps s LEFT JOIN depts d ON d.code = s.dept_code;ERROR 1048 (23000): Column 'dept_name' cannot be nullSELECT s.id, s.dept_code, d.name AS dept_name
FROM stg_emps s LEFT JOIN depts d ON d.code = s.dept_code
WHERE d.code IS NULL;+------+-----------+-----------+
| id | dept_code | dept_name |
+------+-----------+-----------+
| 2 | D30 | NULL |
+------+-----------+-----------+
1 row in set (0.00 sec)Filtering unmatched rows with d.code IS NULL shows employee 2 with D30. That code is missing from the code table.
INSERT INTO depts VALUES ('D30', 'Logistics');Query OK, 1 row affected (0.01 sec)After adding D30 to the code table, both rows were inserted. If the code itself is wrong, fix the staging data. Switching to INNER JOIN removes the error but silently drops that row.
INSERT INTO emps (id, name, dept_name)
SELECT s.id, s.name, d.name
FROM stg_emps s LEFT JOIN depts d ON d.code = s.dept_code;
SELECT * FROM emps ORDER BY id;Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
+----+------+-----------+
| id | name | dept_name |
+----+------+-----------+
| 1 | Kim | Sales |
| 2 | Lee | Logistics |
+----+------+-----------+
2 rows in set (0.00 sec)FAQ
How do I fix Column cannot be null in MySQL?
Find where the NULL comes from (the INSERT values, the source table, or a subquery) and replace it, for example with COALESCE(col, 'default').
What is the difference between ERROR 1048 and ERROR 1364?
1364: the INSERT leaves the NOT NULL column out and it has no default. 1048: a NULL value is given for that column.
Why does UPDATE with a subquery give Column cannot be null?
For rows where the subquery finds nothing, the result is NULL. Use an UPDATE with JOIN so only matching rows are changed.
Is ERROR 1048 translated?
Yes. With lc_messages ko_KR or ja_JP, MySQL 8.4 shows a Korean or Japanese message.
An UPDATE with SUM() fails with Column cannot be null. Why?
If some target has no rows to add up, SUM() returns NULL. In the run above a customer with no orders caused it, and COALESCE(SUM(...), 0) fixed it.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13