{"record":{"id":"7a169127edeabac5","repo":"cocoindex-io/cocoindex","slug":"primary-key-column-primary-key-r-not-found-in-co","errorCode":null,"errorMessage":"Primary key column {primary_key!r} not found in columns: {list(columns.keys())}","messagePattern":"Primary key column (.+?) not found in columns: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/zvec/_target.py","lineNumber":465,"sourceCode":"    vector fields.\n    \"\"\"\n\n    columns: dict[str, _Column]\n    primary_key: str\n    row_type: type[RowT] | None\n\n    def __init__(\n        self,\n        columns: dict[str, _Column],\n        primary_key: str,\n        *,\n        row_type: type[RowT] | None = None,\n    ) -> None:\n        self.columns = columns\n        self.primary_key = primary_key\n        self.row_type = row_type\n        if primary_key not in columns:\n            raise ValueError(\n                f\"Primary key column {primary_key!r} not found in columns: \"\n                f\"{list(columns.keys())}\"\n            )\n        if columns[primary_key].kind != \"scalar\":\n            raise ValueError(\n                f\"Primary key column {primary_key!r} must be a scalar field, \"\n                f\"got kind {columns[primary_key].kind!r}.\"\n            )\n\n    @classmethod\n    async def from_class(\n        cls,\n        record_type: type[RowT],\n        primary_key: list[str],\n        *,\n        column_overrides: dict[\n            str,\n            ZvecType | ZvecVectorDef | ZvecFtsType | res_schema.VectorSchemaProvider,","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/zvec/_target.py#L447-L483","documentation":"When constructing the collection schema object (via from_class output), the designated primary_key must exist among the resolved columns and be a scalar field. __init__ raises ValueError if the primary key name is not a key in the columns dict.","triggerScenarios":"Passing primary_key=\"id\" when the row class has no field named 'id' (renamed field, wrong name, typo) to collection_target/from_class.","commonSituations":"Renaming a dataclass field without updating primary_key; assuming a default key name; programmatic schema building where the key name comes from config.","solutions":["Set primary_key to the exact name of an existing column","Check the spelling against the declared columns list shown in the message","Make sure the primary key field is a scalar (not vector/fts) column"],"exampleFix":"// before\nthis.collection_target(row_type=Doc, primary_key=\"id\")  # class has field 'doc_id'\n// after\nthis.collection_target(row_type=Doc, primary_key=\"doc_id\")","handlingStrategy":"validation","validationCode":"cols = {n: get_type_hints(Row, include_extras=True) for n in ...}\nassert primary_key in columns, f\"{primary_key!r} not in columns: {list(columns)}\"","typeGuard":null,"tryCatchPattern":"try:\n    schema = ZvecCollection(columns, primary_key=pk)\nexcept ValueError as e:\n    if \"not found in columns\" in str(e):\n        pk = next(iter(columns))\n        schema = ZvecCollection(columns, primary_key=pk)\n    else:\n        raise","preventionTips":["Derive primary_key from the row class fields, not a hardcoded string","Ensure the primary key is a scalar field, not vector/fts","Update primary_key whenever row-class fields are renamed"],"tags":["python","validation","schema","zvec"],"backgroundTag":"missing-required-argument","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}