apache/cassandra · error · InvalidRequestException

table does not exist

Error message

table %s does not exist

What it means

validateTable throws InvalidRequestException('table %s does not exist') when the keyspace exists but contains no table (or view) with the given name. The lookup is done against the keyspace's metadata via getTableOrViewNullable.

Solutions

  1. Verify the table exists with DESCRIBE TABLES / system_schema.tables in that keyspace.
  2. Create the table or fix the name/case in the statement (use quoted identifiers for case-sensitive names).
  3. Ensure schema agreement before issuing statements right after DDL.

Example fix

// before
session.execute("INSERT INTO ks.userevents (id) VALUES (1)"); // table is actually user_events
// after
session.execute("INSERT INTO ks.user_events (id) VALUES (1)");
Defensive patterns

Strategy: validation

Validate before calling

boolean tableExists(Session s, String ks, String table) {
    return s.execute("SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?",
                     ks.toLowerCase(), table.toLowerCase()).one() != null;
}

Try / catch

try { session.execute(query); }
catch (InvalidRequestException e) {
    if (e.getMessage() != null && e.getMessage().contains("does not exist"))
        logger.error("Table {}.{} missing — check migrations/typos", ks, table);
    throw e;
}

Prevention

When it happens

Trigger: Querying/altering a table that was never created or was dropped; case mismatch (quoted "Events" vs events); referencing a view name where only a table exists; statement targeting the wrong keyspace.

Common situations: Typos in table names, migrations out of order (table creation not yet run), a replica with lagging schema answering before table creation propagates, ORMs mapping entities to missing tables.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src/java/org/apache/cassandra/schema/SchemaProvider.java:106

    }

    default Keyspaces getNonLocalStrategyKeyspaces()
    {
        return distributedKeyspaces().filter(keyspace -> keyspace.params.replication.klass != LocalStrategy.class);
    }

    default TableMetadata validateTable(String keyspaceName, String tableName)
    {
        if (tableName.isEmpty())
            throw new InvalidRequestException("non-empty table is required");

        KeyspaceMetadata keyspace = getKeyspaceMetadata(keyspaceName);
        if (keyspace == null)
            throw new KeyspaceNotDefinedException(String.format("keyspace %s does not exist", keyspaceName));

        TableMetadata metadata = keyspace.getTableOrViewNullable(tableName);
        if (metadata == null)
            throw new InvalidRequestException(String.format("table %s does not exist", tableName));

        return metadata;
    }

    default ColumnFamilyStore getColumnFamilyStoreInstance(TableId id)
    {
        TableMetadata metadata = getTableMetadata(id);
        if (metadata == null)
            return null;

        Keyspace instance = getKeyspaceInstance(metadata.keyspace);
        if (instance == null)
            return null;

        return instance.hasColumnFamilyStore(metadata.id)
               ? instance.getColumnFamilyStore(metadata.id)
               : null;
    }

View on GitHub (pinned to 88fd0f6a0e)