{"record":{"id":"f9d89eaa273d50ac","repo":"cocoindex-io/cocoindex","slug":"primary-key-primary-key-r-not-found-in-columns-f9d89e","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":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/neo4j/_target.py","lineNumber":382,"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":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/neo4j/_target.py#L364-L400","documentation":"This ValueError is raised by TableSchema's __init__ when the designated primary_key column is not present among the schema's columns. The primary key anchors row identity and change detection, so it must name an existing column. The message lists the available column names sorted, to make the typo obvious.","triggerScenarios":"Constructing TableSchema(columns=[...], primary_key=\"key\") where \"key\" is not in columns — e.g. a default primary_key=\"id\" while the record type has no 'id' field, or passing column_overrides that renamed/removed the key column.","commonSituations":"Renaming the id field in a dataclass without updating primary_key; relying on the default primary_key=\"id\" for a record with a differently named key; building columns from a subset of record fields that excluded the key.","solutions":["Pass primary_key=\"<existing column name>\" matching one of the columns.","Add an 'id' field to the record type if you want the default.","Print the columns list (shown in the error) and fix the key name typo."],"exampleFix":"// before\nTableSchema(columns={\"uid\": ..., \"name\": ...}, primary_key=\"id\")\n// after\nTableSchema(columns={\"uid\": ..., \"name\": ...}, primary_key=\"uid\")","handlingStrategy":"validation","validationCode":"if primary_key not in columns:\n    raise ValueError(f\"primary_key {primary_key!r} must be one of {sorted(columns)}\")","typeGuard":null,"tryCatchPattern":"try:\n    schema = TableSchema(columns=columns, primary_key=pk)\nexcept ValueError as e:\n    raise RuntimeError(f\"bad primary key; available columns: {sorted(columns)}\") from e","preventionTips":["Default primary_key should match an actual id field in the record type","When renaming a key field, update primary_key in the same commit","Validate primary key presence in a unit test per schema"],"tags":["neo4j","primary-key","schema","validation"],"backgroundTag":"resource-not-found","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"}