mysqldude
Error codes › 1048

MySQL & MariaDB error 1048: Column cannot be null

Error messageColumn '…' cannot be null
Example from our test runs: Column 'name' cannot be null (5.6.51)

The statement explicitly put NULL into a column declared NOT NULL. Unlike a missing value, an explicit NULL is rejected even when the column has a default.

MySQLMariaDB
SymbolER_BAD_NULL_ERRORER_BAD_NULL_ERROR
SQLSTATE2300023000
TypeServer errorServer error
Versionsevery release since 5.0 activeevery release since 5.5 active

What it means

Column 'name' cannot be null. Note the difference from 1364: 1364 is raised when you leave out a NOT NULL column that has no default; 1048 when you send NULL for it. A column default is only used when the column is omitted, never when NULL is supplied explicitly (except for TIMESTAMP columns under the old explicit_defaults_for_timestamp=OFF).

Why it happens

  • The application sends NULL for an empty form field or a missing JSON key.
  • An ORM includes every column in the INSERT, with NULL for unset ones.
  • INSERT … SELECT from a source column that contains NULLs.
  • LOAD DATA with \N in the file for a NOT NULL column.

How to fix it

  • Send a real value, or leave the column out of the INSERT so the default applies.
  • Give the column a sensible default: ALTER TABLE p MODIFY name VARCHAR(20) NOT NULL DEFAULT '';
  • Use COALESCE(src_col, '') in INSERT … SELECT.
  • If NULL is a legitimate value, make the column nullable.

Reproduce it yourself

These steps are the exact test our harness runs. Use a scratch server, never production.

  1. Connect with mysql -u root -p and create a scratch database and the test data:

    CREATE DATABASE demo;
    USE demo;
    CREATE TABLE p (id INT PRIMARY KEY, name VARCHAR(20) NOT NULL);
  2. Run:

    INSERT INTO p VALUES (1, NULL);

You get: Column 'name' cannot be null(11.8.9)

Verified fixes

  1. Supply a value, or give the column a default and omit it

    ALTER TABLE p MODIFY name VARCHAR(20) NOT NULL DEFAULT '';
    INSERT INTO p (id) VALUES (1);
    SELECT COUNT(*) FROM p;

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
Insert NULL into a NOT NULL column
repro
✓ 1048✓ 1048✓ 1048✓ 1048✓ 1048✓ 1048✓ 1048✓ 1048✓ 1048
Supply a value, or give the column a default and omit it
fix
✓✓✓✓✓✓✓✓✓
Insert NULL into a NOT NULL column repro
MySQL 5.6✓ 10485.7✓ 10488.0✓ 10488.4✓ 10489✓ 1048
MariaDB 10.6✓ 104810.11✓ 104811.4✓ 104811.8✓ 1048
Supply a value, or give the column a default and omit it fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9

Related errors

  • 1364 ER_NO_DEFAULT_FOR_FIELDexplained
  • 1366 ER_TRUNCATED_WRONG_VALUE_FOR_FIELDexplained