// MySQL error reference
MySQL error 1050: Table already exists
CREATE TABLE (or RENAME TABLE) uses a name that's already taken in that database by a table or view.
- Error number
1050- Name
ER_TABLE_EXISTS_ERROR- SQLSTATE
42S01- Category
- Databases, tables and columns
What it means
A database can hold only one table or view with a given name. Creating or renaming to a name that exists fails with 1050. Re-running a migration or setup script is the usual trigger.
Common causes
- Running the same
CREATE TABLEscript twice. - A migration that already ran partially.
- A view with the same name as the table you're creating.
How to fix it
-
Make the script idempotent.
CREATE TABLE IF NOT EXISTS audit_log ( id BIGINT AUTO_INCREMENT PRIMARY KEY, msg TEXT ); -
If you meant to replace the table, drop it first (this deletes its data).
DROP TABLE IF EXISTS audit_log;
Related errors
1051Unknown table1060Duplicate column name2714SQL Server: There is already an object namedORA-00955Oracle: name is already used by an existing object42P07PostgreSQL: relation already exists
More databases, tables and columns errors
1049Unknown database1046No database selected1054Unknown column in field list1146Table doesn't exist1091Can't DROP; check that column/key exists1305Function or procedure does not exist1442Trigger can't update its own table
The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.
// fewer errors, faster fixes
Work on MySQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.