apache/cassandra · error · NoKeyspaceError
Not in any keyspace.
Error message
Not in any keyspace.
What it means
The COPY command (do_copy) requires a target keyspace: it uses the keyspace from the COPY statement or the session's current keyspace. If neither exists (no USE was issued and COPY did not specify one), it raises NoKeyspaceError('Not in any keyspace.').
Solutions
- Qualify the table in the COPY statement: COPY ks.table TO 'file.csv'.
- Run USE <keyspace> before issuing COPY.
- Fix scripts to always set a keyspace at session start.
- If the keyspace was dropped, recreate it or point the session at a valid one.
Example fix
// before COPY users TO 'users.csv'; -- NoKeyspaceError (no USE issued) // after USE my_ks; COPY users TO 'users.csv'; // or COPY my_ks.users TO 'users.csv';
Defensive patterns
Strategy: validation
Validate before calling
if parsed.get_binding('ksname') is None and shell.current_keyspace is None:
raise ValueError("COPY requires a keyspace: USE one or qualify ks.table") Type guard
def copy_has_keyspace(shell, ksname_binding):
return ksname_binding is not None or shell.current_keyspace is not None Try / catch
try:
shell.do_copy(statement)
except NoKeyspaceError:
# prompt: run USE <keyspace> or qualify COPY ks.table
pass Prevention
- Always qualify COPY as ks.table in scripts.
- Start sessions with an explicit USE statement.
- Remember DROP KEYSPACE clears the session's current keyspace context.
When it happens
Trigger: Running COPY <table> TO/FROM without a 'COPY ks.table' qualification while the session has no current keyspace (no USE executed, or the keyspace was dropped clearing context).
Common situations: Fresh cqlsh session where the user immediately runs COPY without USE; scripts copied from examples that omit the keyspace; session whose keyspace was dropped by another client.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Keyspace %r not found.
- ' ' not found in keyspaces
- Can not create a keyspace with MetaReplicationStrategy
- can't interpret %r as a date with format
- Can't open %r for reading: no matching file found
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/164f0a81e2881638.
Report an issue: GitHub.
Appendix: source
Thrown at pylib/cqlshlib/cqlshmain.py:1420
PAGETIMEOUT=10 - the page timeout in seconds for fetching results
BEGINTOKEN='' - the minimum token string to consider when exporting data
ENDTOKEN='' - the maximum token string to consider when exporting data
MAXREQUESTS=6 - the maximum number of requests each worker process can work on in parallel
MAXOUTPUTSIZE='-1' - the maximum size of the output file measured in number of lines,
beyond this maximum the output file will be split into segments,
-1 means unlimited.
FLOATPRECISION=5 - the number of digits displayed after the decimal point for cql float values
DOUBLEPRECISION=12 - the number of digits displayed after the decimal point for cql double values
When entering CSV data on STDIN, you can use the sequence "\."
on a line by itself to end the data input.
"""
ks = self.cql_unprotect_name(parsed.get_binding('ksname', None))
if ks is None:
ks = self.current_keyspace
if ks is None:
raise NoKeyspaceError("Not in any keyspace.")
table = self.cql_unprotect_name(parsed.get_binding('cfname'))
columns = parsed.get_binding('colnames', None)
if columns is not None:
columns = list(map(self.cql_unprotect_name, columns))
else:
# default to all known columns
columns = self.get_column_names(ks, table)
fname = parsed.get_binding('fname', None)
if fname is not None:
fname = self.cql_unprotect_value(fname)
copyoptnames = list(map(str.lower, parsed.get_binding('optnames', ())))
copyoptvals = list(map(self.cql_unprotect_value, parsed.get_binding('optvals', ())))
opts = dict(list(zip(copyoptnames, copyoptvals)))
direction = parsed.get_binding('dir').upper()
if direction == 'FROM':View on GitHub (pinned to 88fd0f6a0e)