{"record":{"id":"21baa3457fcf8564","repo":"cocoindex-io/cocoindex","slug":"primary-key-primary-key-r-does-not-match-schema-21baa3","errorCode":null,"errorMessage":"primary_key {primary_key!r} does not match schema's {table_schema.primary_key!r}","messagePattern":"primary_key (.+?) does not match schema's (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/neo4j/_target.py","lineNumber":1441,"sourceCode":"    )\n    return _table_provider.target_state(key, spec)\n\n\ndef declare_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) -> TableTarget[RowT, coco.PendingS]:\n    \"\"\"Declare a node table target.\n\n    Use this for tables that exist only as relationship endpoints — no\n    records flow into this declaration's own handler.\n    \"\"\"\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 schema's \"\n            f\"{table_schema.primary_key!r}\"\n        )\n    pk = table_schema.primary_key if table_schema is not None else primary_key\n    provider = coco.declare_target_state_with_child(\n        table_target(\n            db, table_name, table_schema, primary_key=pk, managed_by=managed_by\n        )\n    )\n    return TableTarget(provider, table_schema, table_name, pk)\n\n\nasync def mount_table_target(\n    db: ContextKey[ConnectionFactory],\n    table_name: str,\n    table_schema: TableSchema[RowT] | None = None,\n    *,\n    primary_key: str = \"id\",","sourceCodeStart":1423,"sourceCodeEnd":1459,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/neo4j/_target.py#L1423-L1459","documentation":"declare_table_target() checks that the primary_key argument agrees with the provided table_schema.primary_key before declaring the table target state. A mismatch means the declared relationship endpoint would use a different key than the schema, so the call is rejected.","triggerScenarios":"Calling declare_table_target(..., primary_key=\"id\", table_schema=schema) where schema.primary_key differs.","commonSituations":"Declaring a relationship-endpoint table using defaults while the shared schema declares another PK; copying a call from another table with a different PK.","solutions":["Pass primary_key=schema.primary_key.","Drop the explicit primary_key and rely on table_schema alone (pk falls back to schema's).","Fix the schema's primary_key if it is wrong."],"exampleFix":"// before\nneo4j.declare_table_target(db, \"Person\", primary_key=\"id\", table_schema=schema)\n// after\nneo4j.declare_table_target(db, \"Person\", primary_key=schema.primary_key, table_schema=schema)","handlingStrategy":"validation","validationCode":"pk = table_schema.primary_key if table_schema is not None else \"id\"\nneo4j.declare_table_target(db, \"Person\", primary_key=pk, table_schema=table_schema)","typeGuard":null,"tryCatchPattern":"try:\n    neo4j.declare_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":["Derive primary_key from the schema object rather than hardcoding \"id\".","Centralize table definitions so endpoint tables share the same schema instance."],"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"}