Error
Error Code: 1060

MariaDB Error 1060: Duplicate Column Name

📦 MariaDB
📋

Description

MariaDB Error 1060 indicates that you are attempting to define or add a column to a table with a name that already exists within that same table. This error typically occurs during schema modification operations, such as creating a new table or altering an existing one.
💬

Error Message

Duplicate column name '%s'
🔍

Known Causes

3 known causes
⚠️
Duplicate Column Definition
When executing a CREATE TABLE statement, the table definition includes two or more columns with identical names.
⚠️
Adding Existing Column Name
An ALTER TABLE ADD COLUMN statement attempts to introduce a column whose name is already present in the target table.
⚠️
Schema Migration Conflict
Automated schema migration scripts or version control systems apply a column addition that has already been executed on the database.
🛠️

Solutions

2 solutions available

1. Rename Duplicate Column easy

Use unique column names

1
Fix duplicate column in CREATE TABLE
-- Wrong:
CREATE TABLE users (id INT, name VARCHAR(100), name VARCHAR(100));

-- Correct:
CREATE TABLE users (id INT, first_name VARCHAR(100), last_name VARCHAR(100));

2. Check Existing Columns Before ALTER easy

Verify column doesn't already exist

1
List existing columns
DESCRIBE table_name;
2
Check if column exists before adding
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'database_name'
AND TABLE_NAME = 'table_name'
AND COLUMN_NAME = 'new_column';
🔗

Related Errors

5 related errors