{"record":{"id":"a27e6f5bf0f3b1d5","repo":"apache/cassandra","slug":"no-definition-found-that-is-not-part-of-the-primar","errorCode":null,"errorMessage":"No definition found that is not part of the PRIMARY KEY","messagePattern":"No definition found that is not part of the PRIMARY KEY","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java","lineNumber":444,"sourceCode":"\n        return builder;\n    }\n\n    private void validateCompactTable(List<ColumnProperties> clusteringColumnProperties,\n                                      Map<ColumnIdentifier, ColumnProperties> columns)\n    {\n        boolean isDense = !clusteringColumnProperties.isEmpty();\n\n        if (columns.values().stream().anyMatch(c -> c.type.isMultiCell()))\n            throw ire(\"Non-frozen collections and UDTs are not supported with COMPACT STORAGE\");\n        if (!staticColumns.isEmpty())\n            throw ire(\"Static columns are not supported in COMPACT STORAGE tables\");\n\n        if (clusteringColumnProperties.isEmpty())\n        {\n            // It's a thrift \"static CF\" so there should be some columns definition\n            if (columns.isEmpty())\n                throw ire(\"No definition found that is not part of the PRIMARY KEY\");\n        }\n\n        if (isDense)\n        {\n            // We can have no columns (only the PK), but we can't have more than one.\n            if (columns.size() > 1)\n                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(), \", \")));\n        }\n        else\n        {\n            // we are in the \"static\" case, so we need at least one column defined. For non-compact however, having\n            // just the PK is fine.\n            if (columns.isEmpty())\n                throw ire(\"COMPACT STORAGE with non-composite PRIMARY KEY require one column not part of the PRIMARY KEY, none given\");\n        }\n    }\n\n    private void fixupCompactTable(List<ColumnProperties> clusteringTypes,","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java#L426-L462","documentation":"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.","triggerScenarios":"CREATE TABLE t (pk int PRIMARY KEY) WITH COMPACT STORAGE — no clustering key and no value columns.","commonSituations":"Generating a schema programmatically and emitting a compact table with only a partition key; stripping all value columns from a legacy compact table.","solutions":["Add at least one non-primary-key column to the table.","Remove COMPACT STORAGE, since plain tables may contain only primary-key columns."],"exampleFix":"// before\nCREATE TABLE t (pk int PRIMARY KEY) WITH COMPACT STORAGE;\n// after\nCREATE TABLE t (pk int PRIMARY KEY, value text) WITH COMPACT STORAGE;","handlingStrategy":"validation","validationCode":"// A compact table without clustering columns needs at least one non-PK column:\nboolean compactStorage = true;\nboolean hasClustering = false;\nint nonPkColumnCount = 0;\nif (compactStorage && !hasClustering && nonPkColumnCount == 0) throw new IllegalArgumentException(\"Add a non-PK column or drop COMPACT STORAGE\");","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["Always define at least one value column in compact static CF tables.","Validate generated schemas for empty compact tables.","Drop COMPACT STORAGE for key-only tables."],"tags":["cql","schema","compact-storage"],"backgroundTag":"schema-validation-failed","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"}