{"record":{"id":"61dde1d2c7135126","repo":"apache/cassandra","slug":"keyspace-s-doesn-t-exist","errorCode":null,"errorMessage":"Keyspace %s doesn't exist","messagePattern":"Keyspace (.+?) doesn't exist","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/CQL3Type.java","lineNumber":696,"sourceCode":"\n        public String keyspace()\n        {\n            return null;\n        }\n\n        public Raw freeze()\n        {\n            String message = String.format(\"frozen<> is only allowed on collections, tuples, and user-defined types (got %s)\", this);\n            throw new InvalidRequestException(message);\n        }\n\n        public abstract void validate(ClientState state, String name);\n\n        public CQL3Type prepare(String keyspace)\n        {\n            KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(keyspace);\n            if (ksm == null)\n                throw new ConfigurationException(String.format(\"Keyspace %s doesn't exist\", keyspace));\n            return prepare(keyspace, ksm.types);\n        }\n\n        public abstract CQL3Type prepare(String keyspace, Types udts) throws InvalidRequestException;\n\n        public CQL3Type prepareInternal(String keyspace, Types udts) throws InvalidRequestException\n        {\n            return prepare(keyspace, udts);\n        }\n\n        public boolean referencesUserType(String name)\n        {\n            return false;\n        }\n\n        public static Raw from(CQL3Type type)\n        {\n            return new RawType(type, false);","sourceCodeStart":678,"sourceCodeEnd":714,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/CQL3Type.java#L678-L714","documentation":"CQL3Type.Raw.prepare(keyspace) resolves unqualified UDT references against the given keyspace's metadata. If Schema.instance has no metadata for that keyspace, ConfigurationException('Keyspace <name> doesn't exist') is thrown — the statement references a keyspace that is not defined in the cluster schema.","triggerScenarios":"Preparing a type reference (e.g. a UDT in a CREATE TABLE or INSERT) with a keyspace that was never created, was dropped, or is misspelled; USE-less statements executed against the wrong cluster.","commonSituations":"Typos in the keyspace name; running DDL scripts out of order (UDT/keyspace creation script not applied yet); environment drift where the keyspace exists in dev but not prod.","solutions":["Create the keyspace first (CREATE KEYSPACE ...) or correct the spelling of the keyspace name","Check schema consistency: run DESC KEYSPACES / system_schema.keyspace to confirm existence","Ensure migration scripts run in order so the keyspace exists before statements referencing it"],"exampleFix":"// before\nCREATE TABLE mydata.t (k int PRIMARY KEY, v frozen<mydata.address>); // mydata missing\n// after\nCREATE KEYSPACE IF NOT EXISTS mydata WITH replication = {'class':'SimpleStrategy','replication_factor':1};\nCREATE TABLE mydata.t (k int PRIMARY KEY, v frozen<mydata.address>);","handlingStrategy":"try-catch","validationCode":"KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(keyspace);\nif (ksm == null) throw new IllegalStateException(\"Run CREATE KEYSPACE for \" + keyspace + \" first\");","typeGuard":null,"tryCatchPattern":"try { session.execute(stmt); } catch (ConfigurationException e) { if (e.getMessage().contains(\"doesn't exist\")) { createKeyspace(keyspace); session.execute(stmt); } }","preventionTips":["Create keyspaces (and UDTs) before running dependent DDL","Verify keyspace names against DESC KEYSPACES in each environment","Keep migration scripts idempotent and ordered (CREATE KEYSPACE IF NOT EXISTS)"],"tags":["cassandra","cql","schema","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"}