MySQL Error Troubleshooting
Find MySQL error fixes by code or message, with practical guides for SQL syntax, data changes, and foreign key constraints.
When a MySQL statement fails, note the numeric error code, SQLSTATE, full message, and server version. The same schema problem can have a generic message in one release and a more specific error in another. The MySQL server error reference lists the codes and messages for MySQL 8.4.
Data changes and column values
- Error 1048: a column cannot be
NULL - Error 1264: a numeric value is outside the column range
- Error 1175: safe update mode blocked the statement
- Error 1062: duplicate entry for a primary or unique key
- Error 1136: column and value counts differ in an
INSERT - Error 1136 at row 2 in a multi-row
VALUESstatement - Error 1364: a required field has no default value
- Error 1406: data is too long for a column
Queries and SQL syntax
- Error 1054: unknown column in a
UNIONquery’sORDER BY - Error 1055: a selected column is not allowed by
ONLY_FULL_GROUP_BY - Error 1064: SQL syntax error
- Error 1093: an
UPDATEsubquery reads the target table - Error 1222:
UNIONqueries return different column counts - Error 1250: a table name is not allowed in the global
ORDER BYof aUNION - Error 3942: an empty row in a
VALUEStable constructor
Transactions and locks
- Error 1206: InnoDB lock table full
- Error 1213: deadlock found when trying to get a lock
- Error 1205: lock wait timeout exceeded
Foreign key constraints
These errors occur at different stages. Error 1215 is a generic foreign-key definition failure; Error 1822 names a missing index in the referenced parent table; Error 3780 identifies incompatible child and parent column definitions. Error 1452 instead means a child row has no matching parent row.
- Error 1215: cannot add a foreign key constraint
- Error 1821: missing index in the child (foreign) table
- Error 1822: missing index in the referenced table
- Error 3780: incompatible foreign key columns
- Error 1451: a parent row cannot be deleted or updated while children reference it
- Error 1452: a child row has no matching parent
- MySQL foreign key guide