Error
Error Code:
1050
MariaDB Error 1050: Table Already Exists
Description
MariaDB Error 1050, 'Table '%s' already exists', occurs when an SQL statement attempts to create a new table using a name that is already in use within the current database context. This error typically happens during schema initialization, migration, or manual table creation operations.
Error Message
Table '%s' already exists
Known Causes
4 known causesManual Schema Re-creation
A user or process manually executed a `CREATE TABLE` statement for a table that already exists in the database.
Scripted Schema Duplication
An application or database migration script attempted to create a table without checking for its prior existence, leading to a duplicate creation attempt.
Incorrect Database Context
The `CREATE TABLE` statement was executed while connected to the wrong database, where a table with the specified name already exists.
Case Sensitivity Mismatch
On systems configured for case-insensitive table names, attempting to create a table with a name that differs only by case from an existing table can trigger this error.
Solutions
3 solutions available1. Use IF NOT EXISTS easy
Prevent error with existence check
1
Add IF NOT EXISTS to CREATE TABLE
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100)
);
2. Drop and Recreate easy
Remove existing table first
1
Drop table before creating
DROP TABLE IF EXISTS users;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100)
);
3. Use Different Table Name easy
Choose a unique name
1
List existing tables and choose different name
SHOW TABLES;
CREATE TABLE users_v2 (...);