{"record":{"id":"176ecb397da587d3","repo":"apache/cassandra","slug":"keyspace-s-doesn-t-exist-176ecb","errorCode":null,"errorMessage":"Keyspace '%s' doesn't exist","messagePattern":"Keyspace '(.+?)' doesn't exist","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTriggerStatement.java","lineNumber":85,"sourceCode":"            InvalidRequestException thrown = ire(\"Trigger class '%s' couldn't be loaded during validation. Reason : %s.\", triggerClass, e.getMessage());\n            thrown.initCause(e);\n            throw thrown;\n        }\n    }\n\n    @Override\n    public boolean compatibleWith(ClusterMetadata metadata)\n    {\n        return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);\n    }\n\n    @Override\n    public Keyspaces apply(ClusterMetadata metadata)\n    {\n        Keyspaces schema = metadata.schema.getKeyspaces();\n        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);\n        if (null == keyspace)\n            throw ire(\"Keyspace '%s' doesn't exist\", keyspaceName);\n\n        TableMetadata table = keyspace.getTableOrViewNullable(tableName);\n        if (null == table)\n            throw ire(\"Table '%s' doesn't exist\", tableName);\n\n        if (table.isView())\n            throw ire(\"Cannot CREATE TRIGGER for a materialized view\");\n\n        TriggerMetadata existingTrigger = table.triggers.get(triggerName).orElse(null);\n        if (null != existingTrigger)\n        {\n            if (ifNotExists)\n                return schema;\n\n            throw ire(\"Trigger '%s' already exists\", triggerName);\n        }\n\n        try","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTriggerStatement.java#L67-L103","documentation":"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.","triggerScenarios":"CREATE TRIGGER trg ON missing_ks.tbl USING 'cls'; — or an unqualified table name whose default keyspace (from USE / connection) does not exist.","commonSituations":"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.","solutions":["Correct the keyspace name in the statement","Qualify the table name explicitly: CREATE TRIGGER trg ON mykeyspace.mytable USING '...'","Run DESCRIBE KEYSPACES (or query system_schema.keyspaces) to confirm the keyspace exists before executing DDL"],"exampleFix":"// before\nCREATE TRIGGER trg ON orders.tbl USING 'com.example.Trig';\n// after (keysapce typo corrected)\nCREATE TRIGGER trg ON order_data.tbl USING 'com.example.Trig';","handlingStrategy":"validation","validationCode":"const ks = await session.execute(\"SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = ?\", [keyspace]);\nif (ks.rows.length === 0) throw new Error(`Keyspace ${keyspace} does not exist`);","typeGuard":null,"tryCatchPattern":"try { session.execute(triggerDdl); } catch (e) { if (/Keyspace '.*' doesn't exist/.test(e.message)) { /* create keyspace or fix the name */ } else throw e; }","preventionTips":["Qualify trigger DDL with an explicit keyspace name","Check system_schema.keyspaces before running DDL","Keep environment keyspaces consistent across dev/prod"],"tags":["cql","trigger","keyspace"],"backgroundTag":"entity-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}