Duplicate column name
Error 1060 (SQLSTATE 42S21) is raised by ALTER TABLE or CREATE TABLE when two or more columns in the same table definition share identical names. Column names must be unique within a table.
- 1ALTER TABLE ADD COLUMN specifies a name that already exists
- 2CREATE TABLE DDL has a duplicate column name — often a copy-paste error
- 3A migration script runs twice without a guard
Adding a column that already exists to a table.
ALTER TABLE users ADD COLUMN email VARCHAR(255); -- 'email' column already exists on users table
expected output
ERROR 1060 (42S21): Duplicate column name 'email'
Fix
Check if column exists before adding
WHEN In migration scripts that may run more than once.
-- Check first: SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'users' AND COLUMN_NAME = 'email'; -- Or in MariaDB 10.3.3+ use IF NOT EXISTS: ALTER TABLE users ADD COLUMN IF NOT EXISTS email VARCHAR(255);
Why this works
ALTER TABLE … ADD COLUMN IF NOT EXISTS is a MariaDB extension that silently skips the ADD if the column already exists, making migrations idempotent.
✕ Run migration scripts without idempotency guards
Scripts that run twice break deployments with this error.
ADD COLUMN IF NOT EXISTS is supported. MySQL does not support this syntax.
MariaDB Server error code 1060 / ER_DUP_FIELDNAME
MariaDB ALTER TABLE ↗MariaDB IF NOT EXISTS for columns ↗Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev