1050ERRORTier 1 — Safe✅ HIGH confidence

Table already exists

Category: SchemaVersions: All MariaDB / MySQL versions

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

  1. 1Running a CREATE TABLE migration that was already executed on this environment
  2. 2A migration tool executed the CREATE TABLE twice
  3. 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.

trigger — this will ERROR
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);
ERROR 1050 (42S01): Table 'users' already exists

Fix 1: Use IF NOT EXISTS

In idempotent migrations that may run multiple times.

fix
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

📄 Reference pages

CREATE TABLE IF NOT EXISTS
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →