Key name doesn't exist in table
Production Risk
Low — DDL fails; existing indexes are unchanged.
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.
- 1Typo in the index name in the ALTER TABLE statement
- 2Index was already dropped in a previous migration
- 3Index name differs between environments (dev vs. production)
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.
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.
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.
✕ 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.
ALTER TABLE ... DROP INDEX IF EXISTS was introduced, enabling idempotent index removal.
MySQL 8.0 — 1176 ER_KEY_DOES_NOT_EXITS
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev