Understanding what went wrong.
WHAT TO DO FIRST
Read the whole message, including the number.
WHY THE NUMBER
It identifies the error precisely, and is searchable.
WHAT COMMON ERRORS MEAN
- Access denied: credentials, host pattern, or privileges
- Unknown database: it does not exist, or the account cannot see it
- Table does not exist: name, case sensitivity, or wrong database
- Duplicate entry: a unique constraint was violated
- Cannot add or update a child row: a foreign key has no matching parent
- Data too long: the value exceeds the column
- Lock wait timeout: another transaction held it too long
- Too many connections: the limit was reached
WHAT CASE SENSITIVITY DEPENDS ON
The operating system, in MySQL.
WHY THAT MATTERS
Code working on one system fails on another.
WHAT TO DO ABOUT IT
Use consistent lower-case names everywhere.
WHAT A DUPLICATE ENTRY ERROR TELLS YOU
Which key was violated, which identifies the constraint.
WHAT A FOREIGN KEY ERROR USUALLY MEANS
Inserting in the wrong order, or referencing something deleted.
WHAT A DATA TOO LONG ERROR REVEALS
A column sized for assumptions that no longer hold.
WHAT TO CHECK BEFORE WIDENING IT
Whether the data is actually valid.
WHAT TO LOG IN APPLICATIONS
The error and the statement, without the parameter values if they are sensitive.