{"record":{"id":"e196ada482352145","repo":"apache/cassandra","slug":"column-with-name-s-doesn-t-exist-on-table-s","errorCode":null,"errorMessage":"Column with name '%s' doesn't exist on table '%s'","messagePattern":"Column with name '(.+?)' doesn't exist on table '(.+?)'","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java","lineNumber":237,"sourceCode":"            if (rawMask != null)\n                ColumnMask.ensureEnabled();\n        }\n\n        @Override\n        public boolean compatibleWith(ClusterMetadata metadata)\n        {\n            return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);\n        }\n\n        @Override\n        public KeyspaceMetadata apply(Epoch epoch, KeyspaceMetadata keyspace, TableMetadata table, ClusterMetadata metadata)\n        {\n            ColumnMetadata column = table.getColumn(columnName);\n\n            if (column == null)\n            {\n                if (!ifColumnExists)\n                    throw ire(\"Column with name '%s' doesn't exist on table '%s'\", columnName, tableName);\n\n                return keyspace;\n            }\n\n            // add all user functions to be able to give a good error message to the user if the alter references\n            // a function from another keyspace\n            UserFunctions.Builder ufBuilder = UserFunctions.builder();\n            for (KeyspaceMetadata ksm : metadata.schema.getKeyspaces())\n                ufBuilder.add(ksm.userFunctions);\n\n            ColumnMask oldMask = table.getColumn(columnName).getMask();\n            ColumnMask newMask = rawMask == null ? null : rawMask.prepare(keyspace.name, table.name, columnName, column.type, ufBuilder.build());\n\n            if (Objects.equals(oldMask, newMask))\n                return keyspace;\n\n            TableMetadata.Builder tableBuilder = table.unbuild().epoch(epoch);\n            tableBuilder.alterColumnMask(columnName, newMask);","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java#L219-L255","documentation":"Thrown by ALTER TABLE ... DROP/RENAME/ALTER column operations when the named column does not exist on the table and IF (the column) EXISTS was not specified. The statement is rejected with an InvalidRequestException naming both column and table.","triggerScenarios":"'ALTER TABLE ks.tbl DROP col' (or RENAME/ALTER col) where table.getColumn(columnName) returns null and ifColumnExists is false","commonSituations":"Migration scripts re-run after the column was already dropped; column-name typos or case sensitivity (unquoted names become lowercase); schema drift between environments (column exists in staging but not prod).","solutions":["Check the column exists: SELECT column_name FROM system_schema.columns WHERE keyspace_name=? AND table_name=?","Use IF EXISTS on the column: ALTER TABLE ks.tbl DROP IF EXISTS col","Fix the column name spelling/case or quote it if mixed-case"],"exampleFix":"// before\nsession.execute(\"ALTER TABLE my_app.events DROP descripton text\");\n// after\nsession.execute(\"ALTER TABLE my_app.events DROP IF EXISTS description\");","handlingStrategy":"validation","validationCode":"ResultSet rs = session.execute(\"SELECT column_name FROM system_schema.columns WHERE keyspace_name=? AND table_name=?\", ks, table);\nboolean exists = rs.all().stream().anyMatch(r -> r.getString(\"column_name\").equals(column.toLowerCase()));\nif (!exists) throw new IllegalStateException(\"Column \" + column + \" missing on \" + ks + \".\" + table);","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(alter);\n} catch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"doesn't exist on table\"))\n        log.warn(\"Column already absent; treating DROP as no-op: {}\", alter);\n    else throw e;\n}","preventionTips":["Use DROP/RENAME ... IF EXISTS for idempotency","Quote mixed-case column names explicitly","Diff schemas across environments before applying migrations"],"tags":["cassandra","cql","ddl","column-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}