{"record":{"id":"aba3d5eb20cde19e","repo":"apache/cassandra","slug":"no-primary-key-specifed-for-table-s-exactly-on","errorCode":null,"errorMessage":"No PRIMARY KEY specifed for table '%s' (exactly one required)","messagePattern":"No PRIMARY KEY specifed for table '(.+?)' \\(exactly one required\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java","lineNumber":586,"sourceCode":"        private final Map<ColumnIdentifier, ColumnConstraints> columnConstraints = new HashMap<>();\n\n        private List<ColumnIdentifier> partitionKeyColumns;\n\n        private final LinkedHashMap<ColumnIdentifier, Boolean> clusteringOrder = new LinkedHashMap<>();\n        public final TableAttributes attrs = new TableAttributes();\n\n        public Raw(QualifiedName name, boolean ifNotExists)\n        {\n            this.name = name;\n            this.ifNotExists = ifNotExists;\n        }\n\n        public CreateTableStatement prepare(ClientState state)\n        {\n            String keyspaceName = name.hasKeyspace() ? name.getKeyspace() : state.getKeyspace();\n\n            if (null == partitionKeyColumns)\n                throw ire(\"No PRIMARY KEY specifed for table '%s' (exactly one required)\", name);\n\n            return new CreateTableStatement(keyspaceName,\n                                            name.getName(),\n                                            rawColumns,\n                                            staticColumns,\n                                            partitionKeyColumns,\n                                            clusteringColumns,\n                                            columnConstraints,\n                                            clusteringOrder,\n                                            attrs,\n                                            ifNotExists,\n                                            useCompactStorage);\n        }\n\n        public String keyspace()\n        {\n            return name.getKeyspace();\n        }","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java#L568-L604","documentation":"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').","triggerScenarios":"Executing CREATE TABLE keyspace.tbl (a int, b text) with no PRIMARY KEY clause at all.","commonSituations":"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.","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()"],"exampleFix":"// before\nCREATE TABLE t (a int, b text);\n// after\nCREATE TABLE t (a int, b text, PRIMARY KEY (a));","handlingStrategy":"validation","validationCode":"if (!/PRIMARY\\s+KEY/i.test(ddl)) throw new Error('CREATE TABLE requires a PRIMARY KEY');","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (e) { if (/No PRIMARY KEY/.test(e.message)) { /* re-generate DDL with PRIMARY KEY clause */ } else throw e; }","preventionTips":["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"],"tags":["cql","schema","primary-key"],"backgroundTag":"missing-required-argument","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}