1060
MySQLERRORNotableDDLHIGH confidence

Duplicate column name

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
trigger — this will error
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 if column exists before adding
-- 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

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.

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors