apache/cassandra · error · InvalidRequestException
Cannot rename column
Error message
Cannot rename column %s to %s in table '%s'; another column with that name already exists
What it means
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.
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
Example fix
// before ALTER TABLE users RENAME user_id TO id; // 'id' already exists // after ALTER TABLE users DROP id; ALTER TABLE users RENAME user_id TO id;
Defensive patterns
Strategy: validation
Validate before calling
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 */ } Try / catch
try { session.execute(renameStmt); } catch (InvalidRequestException e) { if (e.getMessage().contains("another column with that name already exists")) { /* resolve collision */ } else throw e; } Prevention
- 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
When it happens
Trigger: ALTER TABLE t RENAME old TO new where new already exists as any column (key or regular) in the table.
Common situations: 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.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- Cannot rename non PRIMARY KEY column
- Column was not found in table
- ACCESS TO DATACENTERS operations not supported by…
- Cannot add a column ' ' of type , incompatible with…
- Cannot add new field
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/8660e2cdca3e846b.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java:591
ColumnIdentifier newName,
boolean ifColumnsExists,
TableMetadata.Builder tableBuilder,
Views.Builder viewsBuilder)
{
ColumnMetadata column = table.getExistingColumn(oldName);
if (null == column)
{
if (!ifColumnsExists)
throw ire("Column %s was not found in table %s", oldName, table);
return;
}
if (!column.isPrimaryKeyColumn())
throw ire("Cannot rename non PRIMARY KEY column %s", oldName);
if (null != table.getColumn(newName))
{
throw ire("Cannot rename column %s to %s in table '%s'; another column with that name already exists",
oldName,
newName,
table);
}
if (!table.indexes.isEmpty())
AlterTableStatement.validateIndexesForColumnModification(table, oldName, true);
for (ViewMetadata view : keyspace.views.forTable(table.id))
{
if (view.includes(oldName))
{
viewsBuilder.put(viewsBuilder.get(view.name()).withRenamedPrimaryKeyColumn(oldName, newName));
}
}
tableBuilder.renamePrimaryKeyColumn(oldName, newName);
}View on GitHub (pinned to 88fd0f6a0e)