{"record":{"id":"df11b84fefdc7f08","repo":"cocoindex-io/cocoindex","slug":"primary-key-column-pk-not-found-in-columns-l","errorCode":null,"errorMessage":"Primary key column '{pk}' not found in columns: {list(self.columns.keys())}","messagePattern":"Primary key column '(.+?)' not found in columns: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/bigquery/_target.py","lineNumber":127,"sourceCode":"\n    columns: dict[str, ColumnDef]\n    primary_key: list[str]\n    row_type: type[RowT] | None\n\n    def __init__(\n        self,\n        columns: dict[str, ColumnDef],\n        primary_key: list[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\n        for pk in self.primary_key:\n            if pk not in self.columns:\n                raise ValueError(\n                    f\"Primary key column '{pk}' not found in columns: {list(self.columns.keys())}\"\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[str, BigQueryType] | None = None,\n    ) -> \"TableSchema[RowT]\":\n        \"\"\"\n        Create a TableSchema from a record type.\n\n        Args:\n            record_type: A dataclass, NamedTuple, or Pydantic model.\n            primary_key: List of column names that form the primary key.\n            column_overrides: Optional per-column BigQueryType overrides.","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/bigquery/_target.py#L109-L145","documentation":"The BigQuery target constructor validates that every column listed in primary_key exists in the declared columns dict. If a primary key name doesn't match any column, table rows could not be uniquely identified for merge/DML, so __init__ raises immediately with the full column list.","triggerScenarios":"Creating the BigQuery table target (directly via __init__ or via from_class) with primary_key=['id'] while the record type/columns define fields with different names (e.g. 'user_id' or differently-cased 'ID').","commonSituations":"Typos in the key name; renaming a dataclass field without updating primary_key; case sensitivity mismatch between BigQuery column naming and Python field names; column overrides renaming the column but not the key.","solutions":["Make primary_key names match the declared columns exactly (check the list printed in the error).","If you used column_overrides to rename a column, update primary_key to the new name.","Compare against the record type fields: primary_key must be a subset of dataclass/NamedTuple/Pydantic field names.","Fix casing — matching is exact, so 'Id' != 'id'."],"exampleFix":"// before\n@dataclass\nclass Row:\n    user_id: int\n    name: str\ntarget = table_target(client, \"proj.ds.tbl\", Row, primary_key=[\"id\"])  # ValueError\n\n// after\ntarget = table_target(client, \"proj.ds.tbl\", Row, primary_key=[\"user_id\"])","handlingStrategy":"validation","validationCode":"fields = {f.name for f in dataclasses.fields(Row)}\nassert set(primary_key) <= fields, f\"primary keys {set(primary_key) - fields} missing from {fields}\"","typeGuard":null,"tryCatchPattern":"try:\n    target = table_target(client, table, Row, primary_key=pk)\nexcept ValueError as e:\n    logger.error(\"primary key mismatch: %s\", e)\n    raise","preventionTips":["Keep primary_key constants next to the record type definition.","Rename fields and primary keys together (IDE rename refactor).","Watch case sensitivity between Python fields and BigQuery columns."],"tags":["python","bigquery","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"}