1384
MariaDBerrorddlhigh confidence
All parts of a PRIMARY KEY must be NOT NULL
Production Risk
Low — DDL fails; no data affected.
What this means
A column included in a PRIMARY KEY definition allows NULL values.
Why it happens
- 1Defining a PRIMARY KEY on a nullable column
- 2Column default is NULL and PRIMARY KEY is added without first making the column NOT NULL
How to reproduce
trigger — this will error
trigger — this will error
CREATE TABLE t (id INT, PRIMARY KEY (id)); -- id allows NULL by default
expected output
ERROR 1384 (42000): All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead
Fix
Make the PK column NOT NULL
Make the PK column NOT NULL
CREATE TABLE t (id INT NOT NULL, PRIMARY KEY (id));
Why this works
Primary keys require NOT NULL on all component columns.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1384 ER_PRIMARY_CANT_HAVE_NULL
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev