1060ERRORTier 2 — Caution✅ HIGH confidence

Duplicate column name

Category: DDLVersions: All MariaDB / MySQL versions

What this means

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.

Why it happens

  1. 1ALTER TABLE ADD COLUMN specifies a name that already exists
  2. 2CREATE TABLE DDL has a duplicate column name — often a copy-paste error
  3. 3A migration script runs twice without a guard

How to reproduce

Adding a column that already exists to a table.

trigger — this will ERROR
ALTER TABLE users ADD COLUMN email VARCHAR(255);
-- 'email' column already exists on users table
ERROR 1060 (42S21): Duplicate column name 'email'

Fix 1: Check if column exists before adding

In migration scripts that may run more than once.

fix
-- 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.

What not to do

Run migration scripts without idempotency guards

Why it's wrong: Scripts that run twice break deployments with this error.

Version notes

MariaDB 10.3.3+ADD COLUMN IF NOT EXISTS is supported. MySQL does not support this syntax.

Sources

📚 Official docs: https://mariadb.com/kb/en/alter-table/

🔧 Source ref: MariaDB Server error code 1060 / ER_DUP_FIELDNAME

📖 Further reading: MariaDB ALTER TABLE

📖 Further reading: MariaDB IF NOT EXISTS for columns

Confidence assessment

✅ HIGH confidence

Stable.

See also

📄 Reference pages

ALTER TABLEinformation_schema.COLUMNS
⚙️ 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 →