Error
Error Code:
1091
MariaDB Error 1091: Column/Key Does Not Exist
Description
This error indicates that you attempted to drop a column, index, or foreign key that does not exist in the specified table. It commonly occurs during schema modification operations when the database cannot find the object you are trying to remove, preventing the operation from completing.
Error Message
Can't DROP '%s'; check that column/key exists
Known Causes
4 known causesTypographical Error in Name
The column or key name specified in the DROP statement contains a typo, causing it not to match any existing object in the table.
Object Already Dropped
The column, index, or foreign key was previously dropped by another operation or script, and the current statement is attempting to drop it again.
Incorrect Table Context
The DROP statement is being executed against the wrong table, which does not contain the specified column or key.
Case Sensitivity Mismatch
The case of the column/key name in the DROP statement does not match the actual object name due to database or operating system case sensitivity settings.
Solutions
3 solutions available1. Verify Column or Key Name Spelling easy
Double-check the exact spelling of the column or key you're trying to drop.
1
Carefully review the `ALTER TABLE` statement that is failing. Ensure the name of the column or key you are attempting to `DROP` matches precisely the name defined in your table schema. Pay close attention to case sensitivity (though MariaDB column names are generally case-insensitive on most systems, it's good practice to be exact), underscores, and any typos.
2
To confirm the exact names of columns and keys in your table, use the `DESCRIBE` or `SHOW INDEX FROM` commands.
DESCRIBE your_table_name;
SHOW INDEX FROM your_table_name;
3
Once you've identified the correct name, correct your `ALTER TABLE` statement and re-execute it.
ALTER TABLE your_table_name DROP COLUMN correct_column_name;
-- or --
ALTER TABLE your_table_name DROP INDEX correct_index_name;
2. Check if the Column or Key Already Exists easy
Confirm that the column or key you are trying to drop is not already absent from the table.
1
The error message 'Can't DROP '%s'; check that column/key exists' strongly suggests that the object you're trying to remove is no longer present. This can happen if the operation was already successfully executed, or if the schema was modified manually or by another process.
2
Use `DESCRIBE` to check for the existence of the column, or `SHOW INDEX FROM` for keys. If the column or key is not listed, it has already been dropped.
DESCRIBE your_table_name;
SHOW INDEX FROM your_table_name;
3
If the column or key is confirmed to be absent, you can safely remove the `ALTER TABLE ... DROP` statement from your script or process. If you are running a script that might be executed multiple times, consider adding checks to ensure the object exists before attempting to drop it.
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'your_table_name' AND COLUMN_NAME = 'column_to_drop') THEN
ALTER TABLE your_table_name DROP COLUMN column_to_drop;
END IF;
-- For indexes, it's slightly more complex as you need to check INFORMATION_SCHEMA.STATISTICS
3. Inspect Table Schema for Foreign Key Dependencies medium
Ensure no foreign keys are referencing the column or index you intend to drop.
1
If you are trying to drop a column that is part of a foreign key constraint, or an index that is used by a foreign key, MariaDB will prevent the drop operation to maintain data integrity. You must drop the foreign key constraint first.
2
Query the `INFORMATION_SCHEMA.KEY_COLUMN_USAGE` table to find any foreign key constraints that reference the column or index you want to drop.
SELECT CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE REFERENCED_TABLE_NAME = 'your_table_name'
AND REFERENCED_COLUMN_NAME = 'column_to_drop';
-- To check for indexes used by foreign keys, you might need to join with INFORMATION_SCHEMA.STATISTICS and INFORMATION_SCHEMA.TABLE_CONSTRAINTS
3
Once you have identified the `CONSTRAINT_NAME` of the foreign key, drop it using the following syntax:
ALTER TABLE referencing_table_name DROP FOREIGN KEY constraint_name;
4
After successfully dropping the foreign key constraint, you can then proceed to drop the column or index.
ALTER TABLE your_table_name DROP COLUMN column_to_drop;
-- or --
ALTER TABLE your_table_name DROP INDEX index_to_drop;