{"record":{"id":"bf4fd7f641395e4c","repo":"apache/cassandra","slug":"column-s-was-not-found-in-table-s","errorCode":null,"errorMessage":"Column %s was not found in table '%s'","messagePattern":"Column (.+?) was not found in table '(.+?)'","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java","lineNumber":497,"sourceCode":"        {\n            Guardrails.alterTableEnabled.ensureEnabled(\"ALTER TABLE changing columns\", state);\n            TableMetadata.Builder builder = table.unbuild();\n            removedColumns.forEach(c -> dropColumn(keyspace, table, c, ifColumnExists, builder));\n            return keyspace.withSwapped(keyspace.tables.withSwapped(builder.build()));\n        }\n\n        @Override\n        public boolean compatibleWith(ClusterMetadata metadata)\n        {\n            return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);\n        }\n\n        private void dropColumn(KeyspaceMetadata keyspace, TableMetadata table, ColumnIdentifier column, boolean ifExists, TableMetadata.Builder builder)\n        {\n            ColumnMetadata currentColumn = table.getColumn(column);\n            if (null == currentColumn) {\n                if (!ifExists)\n                    throw ire(\"Column %s was not found in table '%s'\", column, table);\n                return;\n            }\n\n            if (currentColumn.isPrimaryKeyColumn())\n                throw ire(\"Cannot drop PRIMARY KEY column %s\", column);\n\n            /*\n             * Cannot allow dropping top-level columns of user defined types that aren't frozen because we cannot convert\n             * the type into an equivalent tuple: we only support frozen tuples currently. And as such we cannot persist\n             * the correct type in system_schema.dropped_columns.\n             */\n            if (currentColumn.type.isUDT() && currentColumn.type.isMultiCell())\n                throw ire(\"Cannot drop non-frozen column %s of user type %s\", column, currentColumn.type.asCQL3Type());\n\n            if (!table.indexes.isEmpty())\n                AlterTableStatement.validateIndexesForColumnModification(table, column, false);\n\n            if (!isEmpty(keyspace.views.forTable(table.id)))","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java#L479-L515","documentation":"This InvalidRequestException is thrown by `ALTER TABLE ... DROP <column>` when the named column does not exist in the table and `IF EXISTS` was not specified for the column. Cassandra validates the schema change before applying it and refuses to drop a non-existent column unless the caller explicitly tolerated a missing column.","triggerScenarios":"Running `ALTER TABLE ks.tbl DROP colname` where colname is misspelled, was already dropped in an earlier migration, or never existed. Also happens in multi-environment deployments where schemas have diverged and a migration script assumes a column is present. The error is skipped only when `DROP IF EXISTS` is used.","commonSituations":"Idempotent migration frameworks re-running a DROP after a partial failure; typo'd column names (case sensitivity: unquoted identifiers are lowercased, so `DROP Email` looks for `email`); environments where a previous migration step was applied out of order.","solutions":["Verify the column exists with `DESCRIBE TABLE ks.tbl` or a query against system_schema.columns, correcting any typo or case-sensitivity issue.","If the drop is intentionally conditional, use `ALTER TABLE ks.tbl DROP IF EXISTS colname` so a missing column is not an error.","If the column was already dropped, remove the redundant statement from the migration script.","Check you are connected to the intended keyspace/table; qualify the table as ks.tbl to rule out keyspace confusion."],"exampleFix":"// before\nALTER TABLE users DROP emial; -- InvalidRequest: column not found\n// after\nALTER TABLE users DROP IF EXISTS email;","handlingStrategy":"validation","validationCode":"// Verify the column exists before dropping\nResultSet rs = session.execute(\n  \"SELECT column_name FROM system_schema.columns WHERE keyspace_name=? AND table_name=? AND column_name=?\",\n  ks, table, column);\nboolean exists = rs.iterator().hasNext();\n// only run ALTER TABLE ... DROP if exists, or use DROP IF EXISTS","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(\"ALTER TABLE ks.tbl DROP \" + column);\n} catch (com.datastax.oss.driver.api.core.servererrors.InvalidQueryException e) {\n    if (e.getMessage().contains(\"was not found in table\")) {\n        log.warn(\"Column already absent; treating drop as no-op\");\n    } else throw e;\n}","preventionTips":["Use `DROP IF EXISTS` for idempotent migrations.","Verify identifier casing: unquoted CQL identifiers are lowercased.","Check system_schema.columns before scripted drops.","Keep environments' schemas in sync with a schema migration tool."],"tags":["cql","schema","alter-table","column-not-found"],"backgroundTag":"entity-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}