apache/cassandra · error · InvalidRequestException

No definition found that is not part of the PRIMARY KEY

Error message

No definition found that is not part of the PRIMARY KEY

What it means

A COMPACT STORAGE table without clustering columns (a Thrift 'static CF') must define at least one column outside the primary key; otherwise there is nowhere to store value data. The validator throws this error when such a table has no non-primary-key columns.

Source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java:444

        return builder;
    }

    private void validateCompactTable(List<ColumnProperties> clusteringColumnProperties,
                                      Map<ColumnIdentifier, ColumnProperties> columns)
    {
        boolean isDense = !clusteringColumnProperties.isEmpty();

        if (columns.values().stream().anyMatch(c -> c.type.isMultiCell()))
            throw ire("Non-frozen collections and UDTs are not supported with COMPACT STORAGE");
        if (!staticColumns.isEmpty())
            throw ire("Static columns are not supported in COMPACT STORAGE tables");

        if (clusteringColumnProperties.isEmpty())
        {
            // It's a thrift "static CF" so there should be some columns definition
            if (columns.isEmpty())
                throw ire("No definition found that is not part of the PRIMARY KEY");
        }

        if (isDense)
        {
            // We can have no columns (only the PK), but we can't have more than one.
            if (columns.size() > 1)
                throw ire(String.format("COMPACT STORAGE with composite PRIMARY KEY allows no more than one column not part of the PRIMARY KEY (got: %s)", StringUtils.join(columns.keySet(), ", ")));
        }
        else
        {
            // we are in the "static" case, so we need at least one column defined. For non-compact however, having
            // just the PK is fine.
            if (columns.isEmpty())
                throw ire("COMPACT STORAGE with non-composite PRIMARY KEY require one column not part of the PRIMARY KEY, none given");
        }
    }

    private void fixupCompactTable(List<ColumnProperties> clusteringTypes,

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Add at least one non-primary-key column to the table.
  2. Remove COMPACT STORAGE, since plain tables may contain only primary-key columns.

Example fix

// before
CREATE TABLE t (pk int PRIMARY KEY) WITH COMPACT STORAGE;
// after
CREATE TABLE t (pk int PRIMARY KEY, value text) WITH COMPACT STORAGE;
Defensive patterns

Strategy: validation

Validate before calling

// A compact table without clustering columns needs at least one non-PK column:
boolean compactStorage = true;
boolean hasClustering = false;
int nonPkColumnCount = 0;
if (compactStorage && !hasClustering && nonPkColumnCount == 0) throw new IllegalArgumentException("Add a non-PK column or drop COMPACT STORAGE");

Try / catch

try { session.execute(ddl); } catch (com.datastax.driver.core.exceptions.InvalidQueryException e) { if (e.getMessage().contains("No definition found that is not part of the PRIMARY KEY")) { /* add a value column */ } else throw e; }

Prevention

When it happens

Trigger: CREATE TABLE t (pk int PRIMARY KEY) WITH COMPACT STORAGE — no clustering key and no value columns.

Common situations: Generating a schema programmatically and emitting a compact table with only a partition key; stripping all value columns from a legacy compact table.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/a27e6f5bf0f3b1d5. Report an issue: GitHub.