apache/cassandra · error · InvalidRequestException

Table '%s' doesn't exist

Error message

Table '%s' doesn't exist

What it means

CREATE INDEX resolved the keyspace but could not find the target table or view: keyspace.getTableOrViewNullable(tableName) returned null, so the statement throws this InvalidRequestException. An index must attach to an existing table or materialized view.

Source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateIndexStatement.java:161

    @Override
    public Keyspaces apply(ClusterMetadata metadata)
    {
        attrs.validate();

        Guardrails.createSecondaryIndexesEnabled.ensureEnabled("Creating secondary indexes", state);

        if (attrs.isCustom && attrs.customClass.equals(SASIIndex.class.getName()) && !DatabaseDescriptor.getSASIIndexesEnabled())
            throw new InvalidRequestException(SASI_INDEX_DISABLED);

        Keyspaces schema = metadata.schema.getKeyspaces();
        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);
        if (null == keyspace)
            throw ire(KEYSPACE_DOES_NOT_EXIST, keyspaceName);

        TableMetadata table = keyspace.getTableOrViewNullable(tableName);
        if (null == table)
            throw ire(TABLE_DOES_NOT_EXIST, tableName);

        if (null != indexName && keyspace.hasIndex(indexName))
        {
            if (ifNotExists)
                return schema;

            throw ire(INDEX_ALREADY_EXISTS, indexName);
        }

        if (table.isCounter())
            throw ire(COUNTER_TABLES_NOT_SUPPORTED);

        if (table.isView())
            throw ire(MATERIALIZED_VIEWS_NOT_SUPPORTED);

        if (keyspace.replicationStrategy.hasTransientReplicas())
            throw new InvalidRequestException(TRANSIENTLY_REPLICATED_KEYSPACE_NOT_SUPPORTED);

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Correct the table name spelling and case (quote with double quotes if it contains capitals)
  2. Create the table before the index, or fix migration ordering
  3. Verify with DESCRIBE TABLES in the keyspace that the table exists

Example fix

// before
CREATE INDEX ON ks.usrers(email);   -- typo
// after
CREATE INDEX ON ks.users(email);
Defensive patterns

Strategy: validation

Validate before calling

ResultSet rs = session.execute("SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?", ks, tbl);
if (rs.all().isEmpty()) throw new IllegalStateException("Table does not exist: " + ks + "." + tbl);

Type guard

boolean tableExists(Session s, String ks, String tbl) { return !s.execute("SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?", ks, tbl).all().isEmpty(); }

Try / catch

try { session.execute(createIndexStmt); } catch (InvalidRequestException e) { if (e.getMessage().startsWith("Table") && e.getMessage().contains("doesn't exist")) { /* fix table name or create table first */ } else throw e; }

Prevention

When it happens

Trigger: CREATE INDEX ON ks.missing_table (col); typo in table name; creating an index before the table's migration runs.

Common situations: Table name typos or case-sensitivity issues (unquoted names are lowercased); migration ordering (index DDL before table DDL); wrong environment missing the table.

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/f35f1baf63ad8f6c. Report an issue: GitHub.