{"record":{"id":"6c95b5db2dcc0f36","repo":"cocoindex-io/cocoindex","slug":"primary-key-primary-key-r-not-found-in-columns","errorCode":null,"errorMessage":"primary_key {primary_key!r} not found in columns ({sorted(columns)!r})","messagePattern":"primary_key (.+?) not found in columns \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/falkordb/_target.py","lineNumber":342,"sourceCode":"    Single-field primary key (named via ``primary_key``, default ``\"id\"``).\n    Compound primary keys are not supported in v1.0.\n    \"\"\"\n\n    columns: dict[str, ColumnDef]\n    primary_key: str\n    row_type: type[RowT] | None\n\n    def __init__(\n        self,\n        columns: dict[str, ColumnDef],\n        *,\n        primary_key: str = \"id\",\n        row_type: type[RowT] | None = None,\n    ) -> None:\n        for col_name in columns:\n            _validate_identifier(col_name, \"column name\")\n        if primary_key not in columns:\n            raise ValueError(\n                f\"primary_key {primary_key!r} not found in columns \"\n                f\"({sorted(columns)!r})\"\n            )\n        self.columns = columns\n        self.primary_key = primary_key\n        self.row_type = row_type\n\n    @property\n    def value_field_names(self) -> list[str]:\n        \"\"\"Column names other than the primary key, in declared order.\"\"\"\n        return [c for c in self.columns if c != self.primary_key]\n\n    @classmethod\n    async def from_class(\n        cls,\n        record_type: type[RowT],\n        *,\n        primary_key: str = \"id\",","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/falkordb/_target.py#L324-L360","documentation":"`TableSchema.__init__` validates that the declared `primary_key` names an actual column in the schema's column mapping. FalkorDB node upserts key records by this column, so a missing primary key is a schema construction error raised immediately with the sorted column list for diagnosis.","triggerScenarios":"Constructing `TableSchema(columns, primary_key=\"key\", ...)` or calling `from_class(record_type, primary_key=\"...\")` where the named key is not a field/column name of the record type.","commonSituations":"Default `primary_key=\"id\"` kept while the dataclass field is named `_id`, `key`, or `uid`; renaming a dataclass field without updating `primary_key`; overriding columns and dropping the key column.","solutions":["Pass `primary_key` matching an existing column name, e.g. `primary_key=\"_id\"`.","Add/rename a field in the record type so the primary key column exists.","Check the sorted column list in the message and align the key to one of them."],"exampleFix":"// before\nclass Doc(NamedTuple):\n    doc_id: str\n    text: str\nTableSchema.from_class(Doc)  # defaults to primary_key=\"id\"\n// after\nTableSchema.from_class(Doc, primary_key=\"doc_id\")","handlingStrategy":"validation","validationCode":"cols = {f.name for f in dataclasses.fields(Row)}\npk = \"doc_id\"\nassert pk in cols, f\"primary_key {pk!r} not in {sorted(cols)}\"\nTableSchema.from_class(Row, primary_key=pk)","typeGuard":null,"tryCatchPattern":"try:\n    schema = falkordb.TableSchema(Row, primary_key=pk)\nexcept ValueError as e:\n    if \"not found in columns\" in str(e):\n        logging.error(\"Align primary_key with a real field name: %s\", e)\n    raise","preventionTips":["Always pass primary_key explicitly; don't rely on the \"id\" default.","Define the key name as a constant shared by the dataclass and call sites.","Rename fields via search-and-replace across schema and target calls together."],"tags":["python","falkordb","schema","primary-key"],"backgroundTag":"schema-validation-failed","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}