apache/cassandra · error · InvalidRequestException
No PRIMARY KEY specifed for table
Error message
No PRIMARY KEY specifed for table '%s' (exactly one required)
What it means
The raw CREATE TABLE statement was prepared without any PRIMARY KEY clause, so partitionKeyColumns is null. Every Cassandra table requires exactly one PRIMARY KEY definition; without it the storage layout is undefined, so preparation fails. Note the message contains a long-standing typo ('specifed').
Solutions
- Add a PRIMARY KEY clause to the CREATE TABLE statement, e.g. PRIMARY KEY (a)
- If using the raw builder API, call setPartitionKeyColumns(...) before prepare()
Example fix
// before CREATE TABLE t (a int, b text); // after CREATE TABLE t (a int, b text, PRIMARY KEY (a));
Defensive patterns
Strategy: validation
Validate before calling
if (!/PRIMARY\s+KEY/i.test(ddl)) throw new Error('CREATE TABLE requires a PRIMARY KEY'); Try / catch
try { session.execute(ddl); } catch (e) { if (/No PRIMARY KEY/.test(e.message)) { /* re-generate DDL with PRIMARY KEY clause */ } else throw e; } Prevention
- Always include PRIMARY KEY in every CREATE TABLE
- In DDL generators, assert the key clause is appended unconditionally
- Lint CQL files for missing PRIMARY KEY
When it happens
Trigger: Executing CREATE TABLE keyspace.tbl (a int, b text) with no PRIMARY KEY clause at all.
Common situations: Hand-written DDL omitting PRIMARY KEY; programmatic schema generation where the key clause is appended conditionally and skipped; copying table definitions and dropping the key line.
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
- Cannot drop PRIMARY KEY column
- COMPACT STORAGE with composite PRIMARY KEY allows no more…
- Duplicate column ' ' in PRIMARY KEY clause for table
- Multiple PRIMARY KEY specified for table
- No PRIMARY KEY specifed for view
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/aba3d5eb20cde19e.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java:586
private final Map<ColumnIdentifier, ColumnConstraints> columnConstraints = new HashMap<>();
private List<ColumnIdentifier> partitionKeyColumns;
private final LinkedHashMap<ColumnIdentifier, Boolean> clusteringOrder = new LinkedHashMap<>();
public final TableAttributes attrs = new TableAttributes();
public Raw(QualifiedName name, boolean ifNotExists)
{
this.name = name;
this.ifNotExists = ifNotExists;
}
public CreateTableStatement prepare(ClientState state)
{
String keyspaceName = name.hasKeyspace() ? name.getKeyspace() : state.getKeyspace();
if (null == partitionKeyColumns)
throw ire("No PRIMARY KEY specifed for table '%s' (exactly one required)", name);
return new CreateTableStatement(keyspaceName,
name.getName(),
rawColumns,
staticColumns,
partitionKeyColumns,
clusteringColumns,
columnConstraints,
clusteringOrder,
attrs,
ifNotExists,
useCompactStorage);
}
public String keyspace()
{
return name.getKeyspace();
}View on GitHub (pinned to 88fd0f6a0e)