{"record":{"id":"109004fa41e458a2","repo":"apache/cassandra","slug":"source-keyspace-s-doesn-t-exist","errorCode":null,"errorMessage":"Source Keyspace '%s' doesn't exist","messagePattern":"Source Keyspace '(.+?)' doesn't exist","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CopyTableStatement.java","lineNumber":128,"sourceCode":"    public AuditLogContext getAuditLogContext()\n    {\n        return new AuditLogContext(AuditLogEntryType.CREATE_TABLE_LIKE, targetKeyspace, targetTableName);\n    }\n\n    @Override\n    public boolean compatibleWith(ClusterMetadata metadata)\n    {\n        return metadata.directory.commonSerializationVersion.isAtLeast(Version.V5);\n    }\n\n    @Override\n    public Keyspaces apply(ClusterMetadata metadata)\n    {\n        Keyspaces schema = metadata.schema.getKeyspaces();\n        KeyspaceMetadata sourceKeyspaceMeta = schema.getNullable(sourceKeyspace);\n\n        if (null == sourceKeyspaceMeta)\n            throw ire(\"Source Keyspace '%s' doesn't exist\", sourceKeyspace);\n\n        TableMetadata sourceTableMeta = sourceKeyspaceMeta.getTableOrViewNullable(sourceTableName);\n\n        if (null == sourceTableMeta)\n            throw ire(\"Source Table '%s.%s' doesn't exist\", sourceKeyspace, sourceTableName);\n\n        if (sourceTableMeta.isIndex())\n            throw ire(\"Cannot use CREATE TABLE LIKE on an index table '%s.%s'.\", sourceKeyspace, sourceTableName);\n\n        if (sourceTableMeta.isView())\n            throw ire(\"Cannot use CREATE TABLE LIKE on a materialized view '%s.%s'.\", sourceKeyspace, sourceTableName);\n\n        KeyspaceMetadata targetKeyspaceMeta = schema.getNullable(targetKeyspace);\n        if (null == targetKeyspaceMeta)\n            throw ire(\"Target Keyspace '%s' doesn't exist\", targetKeyspace);\n\n        if (targetKeyspaceMeta.hasTable(targetTableName))\n        {","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CopyTableStatement.java#L110-L146","documentation":"CREATE TABLE LIKE (CopyTableStatement) requires a source keyspace that exists. apply() looks up the source keyspace in the current schema via schema.getNullable(sourceKeyspace) and throws this InvalidRequestException when it is absent. This is the first existence check before validating the source table and target keyspace.","triggerScenarios":"`CREATE TABLE <target> LIKE <sourceKs>.<sourceTable>` where sourceKeyspace is misspelled, was dropped, or the statement ran against a cluster that never had that keyspace.","commonSituations":"Environment drift (statement written for dev, run in prod without the keyspace); typos; running before the keyspace-creation migration.","solutions":["Verify the keyspace with `DESCRIBE KEYSPACES` or system_schema.keyspaces","Create the source keyspace first if it is genuinely missing (CREATE KEYSPACE ...)","Correct the keyspace name in the LIKE clause","Confirm you are connected to the intended cluster/environment"],"exampleFix":"// before\nCREATE TABLE ks2.t2 LIKE src_ks.t1;\n-- src_ks missing\n\n// after\nCREATE KEYSPACE src_ks WITH replication = {'class':'SimpleStrategy','replication_factor':1};\nCREATE TABLE ks2.t2 LIKE src_ks.t1;","handlingStrategy":"validation","validationCode":"// Ensure source keyspace exists\nconst rows = await session.execute(\n  \"SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = ?\", [srcKs]);\nif (rows.rows.length === 0) throw new Error(`Source keyspace ${srcKs} does not exist`);","typeGuard":"null","tryCatchPattern":"try {\n  session.execute(`CREATE TABLE t2 LIKE ${srcKs}.t1`);\n} catch (e) {\n  if (/Source Keyspace .* doesn't exist/.test(e.message)) {\n    // create or correct the keyspace, then retry\n  } else throw e;\n}","preventionTips":["Check system_schema.keyspaces before CREATE TABLE LIKE","Avoid hardcoding keyspace names across environments; use config","Create keyspaces in an early migration step","DESCRIBE KEYSPACES to sanity-check the connected cluster"],"tags":["cassandra","cql","create-table-like","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"}