{"record":{"id":"284539838fed4dcf","repo":"apache/cassandra","slug":"keyspace-s-doesn-t-exist-284539","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/CreateIndexStatement.java","lineNumber":157,"sourceCode":"    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        attrs.validate();\n\n        Guardrails.createSecondaryIndexesEnabled.ensureEnabled(\"Creating secondary indexes\", state);\n\n        if (attrs.isCustom && attrs.customClass.equals(SASIIndex.class.getName()) && !DatabaseDescriptor.getSASIIndexesEnabled())\n            throw new InvalidRequestException(SASI_INDEX_DISABLED);\n\n        Keyspaces schema = metadata.schema.getKeyspaces();\n        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);\n        if (null == keyspace)\n            throw ire(KEYSPACE_DOES_NOT_EXIST, keyspaceName);\n\n        TableMetadata table = keyspace.getTableOrViewNullable(tableName);\n        if (null == table)\n            throw ire(TABLE_DOES_NOT_EXIST, tableName);\n\n        if (null != indexName && keyspace.hasIndex(indexName))\n        {\n            if (ifNotExists)\n                return schema;\n\n            throw ire(INDEX_ALREADY_EXISTS, indexName);\n        }\n\n        if (table.isCounter())\n            throw ire(COUNTER_TABLES_NOT_SUPPORTED);\n\n        if (table.isView())\n            throw ire(MATERIALIZED_VIEWS_NOT_SUPPORTED);","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateIndexStatement.java#L139-L175","documentation":"CREATE INDEX validates the target keyspace exists before resolving the table. If schema.getNullable(keyspaceName) returns null, it throws this InvalidRequestException because an index cannot be created in a nonexistent keyspace.","triggerScenarios":"CREATE INDEX / CREATE CUSTOM INDEX on table 'ks.tbl' where keyspace ks does not exist; typo in the keyspace name.","commonSituations":"Misspelled keyspace in DDL scripts; running index migrations on a cluster missing the keyspace; connecting to the wrong environment/cluster.","solutions":["Create the keyspace first or correct its spelling (DESCRIBE KEYSPACES to verify)","Ensure USE <keyspace> was issued or the table name is keyspace-qualified correctly","Point the client/cqlsh at the intended cluster where the keyspace exists"],"exampleFix":"// before\nCREATE INDEX ON analytics.users(email);   -- analytics does not exist\n// after\nCREATE KEYSPACE IF NOT EXISTS analytics WITH replication = {'class':'SimpleStrategy','replication_factor':1};\nCREATE INDEX ON analytics.users(email);","handlingStrategy":"validation","validationCode":"ResultSet rs = session.execute(\"SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = ?\", ks);\nif (rs.all().isEmpty()) throw new IllegalStateException(\"Keyspace does not exist: \" + ks);","typeGuard":"boolean keyspaceExists(Session s, String ks) { return !s.execute(\"SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = ?\", ks).all().isEmpty(); }","tryCatchPattern":"try { session.execute(createIndexStmt); } catch (InvalidRequestException e) { if (e.getMessage().startsWith(\"Keyspace\") && e.getMessage().contains(\"doesn't exist\")) { /* create keyspace or fix name */ } else throw e; }","preventionTips":["Verify keyspaces with DESCRIBE KEYSPACES before index DDL","Qualify table names with an explicitly configured keyspace","Order migrations keyspaces -> tables -> indexes"],"tags":["cql","index","keyspace","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}