apache/cassandra · error · InvalidRequestException
Cannot rename non PRIMARY KEY column
Error message
Cannot rename non PRIMARY KEY column %s
What it means
Cassandra only permits renaming PRIMARY KEY columns (partition/clustering key parts). When renameColumn (AlterTableStatement.java:587) sees a non-key column, it throws this InvalidRequest, because renaming regular columns would require rewriting all data and is instead done via ADD/DROP column pairs.
Solutions
- For regular columns, add the new column, copy data with an UPDATE ... SET new = old, then drop the old column
- Rename only key columns, or recreate the table with the desired schema and migrate data
- Use INSERT INTO new_table SELECT-style migration if the table is small
Example fix
// before ALTER TABLE users RENAME email TO contact; // after (regular column) ALTER TABLE users ADD contact text; UPDATE users SET contact = email; ALTER TABLE users DROP email;
Defensive patterns
Strategy: validation
Validate before calling
ColumnMetadata c = Schema.instance.getTableMetadata(ks, table).getColumn(oldName); if (c == null || !c.isPrimaryKeyColumn()) { /* use ADD+copy+DROP instead of RENAME */ } Try / catch
try { session.execute(renameStmt); } catch (InvalidRequestException e) { if (e.getMessage().startsWith("Cannot rename non PRIMARY KEY column")) { /* fall back to add/copy/drop migration */ } else throw e; } Prevention
- Only use RENAME for partition/clustering key columns
- Document in migration tooling that value columns are renamed via ADD/UPDATE/DROP
- Review schema DDL against the table definition before applying
When it happens
Trigger: ALTER TABLE t RENAME some_regular_column TO other; where some_regular_column is not part of PRIMARY KEY. Checked immediately after the column is found to exist.
Common situations: Developers assuming RENAME works like other databases for value columns; trying to rename a static column that is not a key column; migrating SQL habits to CQL.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Cannot rename 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/81af5749ed84ca7d.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java:587
private void renameColumn(KeyspaceMetadata keyspace,
TableMetadata table,
ColumnIdentifier oldName,
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));
}View on GitHub (pinned to 88fd0f6a0e)