{"record":{"id":"8660e2cdca3e846b","repo":"apache/cassandra","slug":"cannot-rename-column-s-to-s-in-table-s-anoth","errorCode":null,"errorMessage":"Cannot rename column %s to %s in table '%s'; another column with that name already exists","messagePattern":"Cannot rename column (.+?) to (.+?) in table '(.+?)'; another column with that name already exists","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java","lineNumber":591,"sourceCode":"                                  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))\n            {\n                if (view.includes(oldName))\n                {\n                    viewsBuilder.put(viewsBuilder.get(view.name()).withRenamedPrimaryKeyColumn(oldName, newName));\n                }\n            }\n\n            tableBuilder.renamePrimaryKeyColumn(oldName, newName);\n        }","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java#L573-L609","documentation":"A rename must produce a unique column name. renameColumn (AlterTableStatement.java:591) throws this InvalidRequest when table.getColumn(newName) already returns a column, because two columns cannot share a name in the table metadata.","triggerScenarios":"ALTER TABLE t RENAME old TO new where new already exists as any column (key or regular) in the table.","commonSituations":"Renaming a key column to a name that collides with an existing regular column; running a migration that adds the target column first and then renames into it; copy-paste mistakes in migration scripts.","solutions":["Choose a distinct newName that does not collide (check system_schema.columns first)","Drop the conflicting existing column if it is no longer needed before renaming","Reorder your migration so the rename happens before adding a column with the target name"],"exampleFix":"// before\nALTER TABLE users RENAME user_id TO id; // 'id' already exists\n// after\nALTER TABLE users DROP id;\nALTER TABLE users RENAME user_id TO id;","handlingStrategy":"validation","validationCode":"Set<String> names = session.execute(\"SELECT column_name FROM system_schema.columns WHERE keyspace_name=? AND table_name=?\", ks, table).all().stream().map(r -> r.getString(\"column_name\")).collect(Collectors.toSet()); if (names.contains(newName)) { /* choose a different target name or drop the conflict */ }","typeGuard":null,"tryCatchPattern":"try { session.execute(renameStmt); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"another column with that name already exists\")) { /* resolve collision */ } else throw e; }","preventionTips":["Generate migrations from the live schema, not from a stale model","Order migration steps so renames precede column additions with the target name","Uniqueness-check target names programmatically before applying"],"tags":["cassandra","cql","schema","alter-table","rename","collision"],"backgroundTag":"file-already-exists","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"}