DBAtlas · Database operations atlas

1091: Can't DROP 'x'; check that column/key exists

MySQL

What does it mean?

The column, index or foreign key being dropped with ALTER TABLE does not exist. A nonexistent object cannot be dropped.

Why does it happen?

Giving a nonexistent object name in DROP COLUMN/INDEX/FOREIGN KEY; a misspelled name; the object already dropped; confusing the foreign key name with the index name; a migration run a second time.

How to fix it

Verify the object's real name: SHOW CREATE TABLE my_table; or SHOW INDEX FROM my_table; Drop it using the correct name. For a foreign key use its symbol name: ALTER TABLE my_table DROP FOREIGN KEY fk_name; MySQL has no DROP COLUMN IF EXISTS syntax (only MariaDB does); in idempotent migrations, first check that the column exists via information_schema.columns: SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'my_table' AND column_name = 'my_column';

Open in DBAtlas →

More from this engine