apache/cassandra · error · InvalidRequestException

Keyspace ' ' doesn't exist

Error message

Keyspace '%s' doesn't exist

What it means

CREATE TRIGGER names a keyspace that does not exist in the current cluster metadata. The statement's apply() looks up keyspaceName in the schema's keyspaces and throws immediately when the lookup returns null, before touching the table.

Solutions

  1. Correct the keyspace name in the statement
  2. Qualify the table name explicitly: CREATE TRIGGER trg ON mykeyspace.mytable USING '...'
  3. Run DESCRIBE KEYSPACES (or query system_schema.keyspaces) to confirm the keyspace exists before executing DDL

Example fix

// before
CREATE TRIGGER trg ON orders.tbl USING 'com.example.Trig';
// after (keysapce typo corrected)
CREATE TRIGGER trg ON order_data.tbl USING 'com.example.Trig';
Defensive patterns

Strategy: validation

Validate before calling

const ks = await session.execute("SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = ?", [keyspace]);
if (ks.rows.length === 0) throw new Error(`Keyspace ${keyspace} does not exist`);

Try / catch

try { session.execute(triggerDdl); } catch (e) { if (/Keyspace '.*' doesn't exist/.test(e.message)) { /* create keyspace or fix the name */ } else throw e; }

Prevention

When it happens

Trigger: CREATE TRIGGER trg ON missing_ks.tbl USING 'cls'; — or an unqualified table name whose default keyspace (from USE / connection) does not exist.

Common situations: Typo in the keyspace name; running DDL against the wrong cluster/environment (dev vs prod); connection without a USE statement so the default keyspace name is not set to anything valid.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateTriggerStatement.java:85

            InvalidRequestException thrown = ire("Trigger class '%s' couldn't be loaded during validation. Reason : %s.", triggerClass, e.getMessage());
            thrown.initCause(e);
            throw thrown;
        }
    }

    @Override
    public boolean compatibleWith(ClusterMetadata metadata)
    {
        return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);
    }

    @Override
    public Keyspaces apply(ClusterMetadata metadata)
    {
        Keyspaces schema = metadata.schema.getKeyspaces();
        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);
        if (null == keyspace)
            throw ire("Keyspace '%s' doesn't exist", keyspaceName);

        TableMetadata table = keyspace.getTableOrViewNullable(tableName);
        if (null == table)
            throw ire("Table '%s' doesn't exist", tableName);

        if (table.isView())
            throw ire("Cannot CREATE TRIGGER for a materialized view");

        TriggerMetadata existingTrigger = table.triggers.get(triggerName).orElse(null);
        if (null != existingTrigger)
        {
            if (ifNotExists)
                return schema;

            throw ire("Trigger '%s' already exists", triggerName);
        }

        try

View on GitHub (pinned to 88fd0f6a0e)