apache/cassandra · error · InvalidRequestException

Column was not found in table

Error message

Column %s was not found in table %s

What it means

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.

Solutions

  1. Verify the current column names with DESCRIBE TABLE or SELECT FROM system_schema.columns and correct the oldName in the RENAME clause
  2. Add IF EXISTS semantics where supported / use ifColumnsExists=true in programmatic alteration to skip missing columns instead of failing
  3. Check you are connected to the intended keyspace and table
  4. If the column was already renamed by an earlier migration, remove the redundant rename statement

Example fix

// before
ALTER TABLE users RENAME usr_name TO user_name;
// after (column verified via system_schema.columns)
ALTER TABLE users RENAME user_name TO display_name;
Defensive patterns

Strategy: validation

Validate before calling

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 */ }

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/5aa87cd1d71142f5. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java:582

            renamedColumns.forEach((o, n) -> renameColumn(keyspace, table, o, n, ifColumnsExists, tableBuilder, viewsBuilder));

            return keyspace.withSwapped(keyspace.tables.withSwapped(tableBuilder.build()))
                           .withSwapped(viewsBuilder.build());
        }

        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))

View on GitHub (pinned to 88fd0f6a0e)