1176
MariaDBERRORCommonDDLHIGH confidence

Key name doesn't exist in table

Production Risk

Low — DDL fails; existing indexes are unchanged.

What this means

ER_KEY_DOES_NOT_EXITS (1176, SQLSTATE 42000) is raised when ALTER TABLE DROP INDEX (or DROP KEY) specifies an index name that does not exist on the table.

Why it happens
  1. 1Typo in the index name in the ALTER TABLE statement
  2. 2Index was already dropped in a previous migration
  3. 3Index name differs between environments (dev vs. production)
How to reproduce
trigger — this will error
trigger — this will error
ALTER TABLE t DROP INDEX nonexistent_index;

expected output

ERROR 1176 (42000): Key 'nonexistent_index' doesn't exist in table 't'

Fix 1

Verify the index name before dropping

WHEN Always.

Verify the index name before dropping
SHOW INDEX FROM t;
-- Then use the correct Key_name value:
ALTER TABLE t DROP INDEX correct_index_name;

Why this works

SHOW INDEX FROM t lists all indexes and their exact Key_name values, preventing typos.

Fix 2

Use IF EXISTS with DROP INDEX (MySQL 8.0+)

WHEN In idempotent migration scripts.

Use IF EXISTS with DROP INDEX (MySQL 8.0+)
ALTER TABLE t DROP INDEX IF EXISTS idx_name;

Why this works

IF EXISTS on DROP INDEX suppresses 1176 when the index does not exist, making the migration safe to re-run.

What not to do

Hard-code index names in migrations without SHOW INDEX verification

Index names may differ between environments; always verify the exact name before referencing it in DDL.

Version notes
MySQL 8.0

ALTER TABLE ... DROP INDEX IF EXISTS was introduced, enabling idempotent index removal.

Sources
Official documentation ↗

MySQL 8.0 — 1176 ER_KEY_DOES_NOT_EXITS

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

← All MariaDB errors