1050ERRORTier 1 — Safe✅ HIGH confidenceTable already exists
What this means
Error 1050 (SQLSTATE 42S01) is raised when a CREATE TABLE statement tries to create a table with a name that already exists in the current database. This commonly occurs during application startup migrations that do not guard with IF NOT EXISTS.
Why it happens
- 1Running a CREATE TABLE migration that was already executed on this environment
- 2A migration tool executed the CREATE TABLE twice
- 3The table name collides with a system or reserved table name
How to reproduce
CREATE TABLE is called for an existing table without IF NOT EXISTS.
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
email VARCHAR(255) NOT NULL
);
-- Running it again:
CREATE TABLE users (id INT PRIMARY KEY AUTO_INCREMENT, email VARCHAR(255) NOT NULL);Fix 1: Use IF NOT EXISTS
In idempotent migrations that may run multiple times.
CREATE TABLE IF NOT EXISTS users (
id INT PRIMARY KEY AUTO_INCREMENT,
email VARCHAR(255) NOT NULL
);Why this works
IF NOT EXISTS causes the server to silently skip the CREATE if the table already exists, making the statement idempotent. No warning is raised in recent versions.
What not to do
Use DROP TABLE before every CREATE TABLE in migrations
Why it's wrong: DROP + CREATE deletes all existing data. In a production migration this would cause catastrophic data loss.
Version notes
All versionsIF NOT EXISTS is available in all supported MariaDB and MySQL versions.Sources
📚 Official docs: https://mariadb.com/kb/en/create-table/
🔧 Source ref: MariaDB Server error code 1050 / ER_TABLE_EXISTS_ERROR
📖 Further reading: MariaDB CREATE TABLE
Confidence assessment
✅ HIGH confidence
Stable.
See also
🔗 Related errors
📄 Reference pages