apache/cassandra · error · InvalidRequestException
Source Keyspace '%s' doesn't exist
Error message
Source Keyspace '%s' doesn't exist
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CopyTableStatement.java:128
public AuditLogContext getAuditLogContext()
{
return new AuditLogContext(AuditLogEntryType.CREATE_TABLE_LIKE, targetKeyspace, targetTableName);
}
@Override
public boolean compatibleWith(ClusterMetadata metadata)
{
return metadata.directory.commonSerializationVersion.isAtLeast(Version.V5);
}
@Override
public Keyspaces apply(ClusterMetadata metadata)
{
Keyspaces schema = metadata.schema.getKeyspaces();
KeyspaceMetadata sourceKeyspaceMeta = schema.getNullable(sourceKeyspace);
if (null == sourceKeyspaceMeta)
throw ire("Source Keyspace '%s' doesn't exist", sourceKeyspace);
TableMetadata sourceTableMeta = sourceKeyspaceMeta.getTableOrViewNullable(sourceTableName);
if (null == sourceTableMeta)
throw ire("Source Table '%s.%s' doesn't exist", sourceKeyspace, sourceTableName);
if (sourceTableMeta.isIndex())
throw ire("Cannot use CREATE TABLE LIKE on an index table '%s.%s'.", sourceKeyspace, sourceTableName);
if (sourceTableMeta.isView())
throw ire("Cannot use CREATE TABLE LIKE on a materialized view '%s.%s'.", sourceKeyspace, sourceTableName);
KeyspaceMetadata targetKeyspaceMeta = schema.getNullable(targetKeyspace);
if (null == targetKeyspaceMeta)
throw ire("Target Keyspace '%s' doesn't exist", targetKeyspace);
if (targetKeyspaceMeta.hasTable(targetTableName))
{View on GitHub (pinned to 88fd0f6a0e)
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
Example fix
// before
CREATE TABLE ks2.t2 LIKE src_ks.t1;
-- src_ks missing
// after
CREATE KEYSPACE src_ks WITH replication = {'class':'SimpleStrategy','replication_factor':1};
CREATE TABLE ks2.t2 LIKE src_ks.t1; Defensive patterns
Strategy: validation
Validate before calling
// Ensure source keyspace exists
const rows = await session.execute(
"SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = ?", [srcKs]);
if (rows.rows.length === 0) throw new Error(`Source keyspace ${srcKs} does not exist`); Type guard
null
Try / catch
try {
session.execute(`CREATE TABLE t2 LIKE ${srcKs}.t1`);
} catch (e) {
if (/Source Keyspace .* doesn't exist/.test(e.message)) {
// create or correct the keyspace, then retry
} else throw e;
} Prevention
- 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
When it happens
Trigger: `CREATE TABLE <target> LIKE <sourceKs>.<sourceTable>` where sourceKeyspace is misspelled, was dropped, or the statement ran against a cluster that never had that keyspace.
Common situations: Environment drift (statement written for dev, run in prod without the keyspace); typos; running before the keyspace-creation migration.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Target Keyspace '%s' doesn't exist
- Source Table '%s.%s' doesn't exist
- Cannot use CREATE TABLE LIKE on an index table '%s.%s'.
- Cannot use CREATE TABLE LIKE on a materialized view '%s.%s'.
- category %s not found in %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/109004fa41e458a2.
Report an issue: GitHub.