Menu

MySQL Error 1048: Column Cannot Be Null

Fix MySQL Error 1048 by supplying a non-NULL value, using DEFAULT for an existing default, or allowing NULL only when the column is optional.

Posted on By
On this page

MySQL Error 1048 (SQLSTATE 23000, ER_BAD_NULL_ERROR) means an INSERT or UPDATE tried to store NULL in a column defined as NOT NULL. MySQL’s error reference gives the message as Column '%s' cannot be null.

Example: an insert explicitly supplies NULL

CREATE TABLE jobs (
  job_id INT AUTO_INCREMENT PRIMARY KEY,
  status VARCHAR(20) NOT NULL DEFAULT 'pending'
);

INSERT INTO jobs (status)
VALUES (NULL);

This raises Error 1048 even though status has a default. A default applies when the column is omitted or the insert uses DEFAULT; an explicit NULL is still a NULL value.

Fix the value or the column definition

If the row should have a status, provide one:

INSERT INTO jobs (status)
VALUES ('queued');

If the existing default is the intended value, request it explicitly:

INSERT INTO jobs (status)
VALUES (DEFAULT);

Check the column definition with SHOW CREATE TABLE jobs; before changing data or schema. If the field is genuinely optional, change the column to allow NULL:

ALTER TABLE jobs
  MODIFY status VARCHAR(20) NULL DEFAULT NULL;

Only make a column nullable when the application and data model permit a missing value. See the MySQL NOT NULL guide for constraint syntax and examples.

  • Error 1048: the statement explicitly supplies NULL for a NOT NULL column.
  • Error 1364: strict SQL mode rejects an omitted required column that has no default. See MySQL Error 1364.
  • Error 1136: the number of supplied values does not match the target columns. See MySQL Error 1136.

For the general INSERT syntax and more common errors, see the MySQL INSERT guide. To understand MySQL’s default-value behavior, see the official data type defaults documentation.