{"record":{"id":"5aa87cd1d71142f5","repo":"apache/cassandra","slug":"column-s-was-not-found-in-table-s-5aa87c","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":582,"sourceCode":"            renamedColumns.forEach((o, n) -> renameColumn(keyspace, table, o, n, ifColumnsExists, tableBuilder, viewsBuilder));\n\n            return keyspace.withSwapped(keyspace.tables.withSwapped(tableBuilder.build()))\n                           .withSwapped(viewsBuilder.build());\n        }\n\n        private void renameColumn(KeyspaceMetadata keyspace,\n                                  TableMetadata table,\n                                  ColumnIdentifier oldName,\n                                  ColumnIdentifier newName,\n                                  boolean ifColumnsExists,\n                                  TableMetadata.Builder tableBuilder,\n                                  Views.Builder viewsBuilder)\n        {\n            ColumnMetadata column = table.getExistingColumn(oldName);\n            if (null == column)\n            {\n                if (!ifColumnsExists)\n                    throw ire(\"Column %s was not found in table %s\", oldName, table);\n                return;\n            }\n\n            if (!column.isPrimaryKeyColumn())\n                throw ire(\"Cannot rename non PRIMARY KEY column %s\", oldName);\n\n            if (null != table.getColumn(newName))\n            {\n                throw ire(\"Cannot rename column %s to %s in table '%s'; another column with that name already exists\",\n                          oldName,\n                          newName,\n                          table);\n            }\n\n            if (!table.indexes.isEmpty())\n                AlterTableStatement.validateIndexesForColumnModification(table, oldName, true);\n\n            for (ViewMetadata view : keyspace.views.forTable(table.id))","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java#L564-L600","documentation":"ALTER TABLE ... RENAME validates that each renamed column exists in the table before applying the change. Cassandra throws this InvalidRequest when the old column name does not match any existing column, since a rename of a non-existent column cannot be applied to the schema. Unlike most schema errors this can be suppressed with IF EXISTS on the column.","triggerScenarios":"ALTER TABLE ... RENAME old TO new where old is misspelled, was already dropped, or belongs to a different table. Raised in AlterTableStatement.renameColumn (line 582) when table.getExistingColumn(oldName) returns null and ifColumnsExists is false.","commonSituations":"Typo in the column name during a schema migration; renaming a column that a previous migration already renamed; running the same idempotent migration script twice without IF EXISTS; renaming a column in the wrong keyspace.","solutions":["Verify the current column names with DESCRIBE TABLE or SELECT FROM system_schema.columns and correct the oldName in the RENAME clause","Add IF EXISTS semantics where supported / use ifColumnsExists=true in programmatic alteration to skip missing columns instead of failing","Check you are connected to the intended keyspace and table","If the column was already renamed by an earlier migration, remove the redundant rename statement"],"exampleFix":"// before\nALTER TABLE users RENAME usr_name TO user_name;\n// after (column verified via system_schema.columns)\nALTER TABLE users RENAME user_name TO display_name;","handlingStrategy":"validation","validationCode":"boolean exists = session.execute(\"SELECT column_name FROM system_schema.columns WHERE keyspace_name=? AND table_name=?\", ks, table).all().stream().anyMatch(r -> r.getString(\"column_name\").equals(oldName)); if (!exists) { /* skip or correct rename */ }","typeGuard":null,"tryCatchPattern":"try { session.execute(\"ALTER TABLE \" + table + \" RENAME \" + old + \" TO \" + new); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"was not found in table\")) { /* treat as already renamed */ } else throw e; }","preventionTips":["Always look up current columns in system_schema.columns before generating a RENAME","Use IF EXISTS-style idempotent migrations for repeatable scripts","Pin migrations to specific keyspace/table pairs to avoid wrong-keyspace mistakes"],"tags":["cassandra","cql","schema","alter-table","rename"],"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"}