{"record":{"id":"4b79900ebd89c307","repo":"cocoindex-io/cocoindex","slug":"primary-key-primary-key-r-does-not-match-the-sch-4b7990","errorCode":null,"errorMessage":"primary_key {primary_key!r} does not match the schema's declared primary_key {table_schema.primary_key!r}","messagePattern":"primary_key (.+?) does not match the schema's declared primary_key (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/neo4j/_target.py","lineNumber":1409,"sourceCode":"\n# ---------------------------------------------------------------------------\n# Module-level entry points\n# ---------------------------------------------------------------------------\n\n\ndef table_target(\n    db: ContextKey[ConnectionFactory],\n    table_name: str,\n    table_schema: TableSchema[RowT] | None = None,\n    *,\n    primary_key: str = \"id\",\n    managed_by: target.ManagedBy = target.ManagedBy.SYSTEM,\n) -> coco.TargetState[_RecordHandler]:\n    \"\"\"Create a ``TargetState`` for a Neo4j node table (label).\"\"\"\n    _validate_identifier(table_name, \"table name\")\n    _validate_identifier(primary_key, \"primary key\")\n    if table_schema is not None and table_schema.primary_key != primary_key:\n        raise ValueError(\n            f\"primary_key {primary_key!r} does not match the schema's \"\n            f\"declared primary_key {table_schema.primary_key!r}\"\n        )\n    key = _TableKey(db_key=db.key, table_name=table_name)\n    spec = _TableSpec(\n        table_schema=table_schema,\n        primary_key=primary_key,\n        is_relation=False,\n        from_label=None,\n        from_pk_field=None,\n        to_label=None,\n        to_pk_field=None,\n        managed_by=managed_by,\n    )\n    return _table_provider.target_state(key, spec)\n\n\ndef declare_table_target(","sourceCodeStart":1391,"sourceCodeEnd":1427,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/neo4j/_target.py#L1391-L1427","documentation":"table_target() validates consistency between the explicit primary_key argument and the optional TableSchema. If both are given and disagree, the library cannot determine which field identifies nodes, so it raises ValueError rather than silently picking one.","triggerScenarios":"Calling table_target(db, table_name=..., primary_key=\"id\", table_schema=schema) where schema.primary_key is a different field name.","commonSituations":"Schema was defined with primary_key=\"key\" while the call site still passes the default primary_key=\"id\"; schema updated after refactoring without updating call sites.","solutions":["Make primary_key match table_schema.primary_key (e.g. primary_key=schema.primary_key).","Omit table_schema if you intend to rely solely on the explicit primary_key.","Update the TableSchema definition if the explicit primary_key is the intended one."],"exampleFix":"// before\ncoco.neo4j.table_target(db, \"Person\", primary_key=\"id\", table_schema=schema)  # schema.primary_key == \"email\"\n// after\ncoco.neo4j.table_target(db, \"Person\", primary_key=schema.primary_key, table_schema=schema)","handlingStrategy":"validation","validationCode":"if table_schema is not None and primary_key != table_schema.primary_key:\n    primary_key = table_schema.primary_key  # reconcile before calling\ncoco.neo4j.table_target(db, \"Person\", primary_key=primary_key, table_schema=table_schema)","typeGuard":null,"tryCatchPattern":"try:\n    coco.neo4j.table_target(db, name, primary_key=pk, table_schema=schema)\nexcept ValueError as e:\n    raise ConfigError(\"primary_key/table_schema mismatch\") from e","preventionTips":["Pass primary_key=schema.primary_key instead of a literal when a schema is provided.","Adopt one convention: either always schema-driven or always explicit PK, not both.","Add a unit test that builds all table targets from the shared schema registry."],"tags":["neo4j","schema","conflict"],"backgroundTag":"conflicting-config-options","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"}