{"record":{"id":"49dfbde51cb18968","repo":"cocoindex-io/cocoindex","slug":"primary-key-primary-key-r-does-not-match-schema","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/falkordb/_target.py","lineNumber":1466,"sourceCode":"        managed_by=managed_by,\n    )\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 (no records flow into this declaration's\n    own handler — typically used to register a table that is referenced as a\n    relationship endpoint by other handlers).\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 {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\",\n    managed_by: target.ManagedBy = target.ManagedBy.SYSTEM,","sourceCodeStart":1448,"sourceCodeEnd":1484,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/falkordb/_target.py#L1448-L1484","documentation":"`declare_table_target` performs the same consistency check as `table_target`: the given `primary_key` must equal `table_schema.primary_key`. This variant registers a table referenced as a relationship endpoint; a mismatched key would corrupt relationship endpoint resolution, so it raises before declaring anything.","triggerScenarios":"Calling `declare_table_target(db, name, table_schema, primary_key=\"x\")` where `\"x\" != table_schema.primary_key`.","commonSituations":"Registering a shared node table for relationships with a hand-typed primary key that drifted from the schema; copy-pasting a `declare_table_target` call between tables with different keys; defaulting to `\"id\"` while the schema uses a domain-specific key.","solutions":["Pass `primary_key=table_schema.primary_key` or omit and let the schema's key be used.","Regenerate the schema so its primary key matches the value you intend to pass.","For relationship-endpoint registration, derive the key from the same schema object used by the main table target."],"exampleFix":"// before\ndeclare_table_target(db, \"Person\", person_schema, primary_key=\"uid\")  # schema uses \"id\"\n// after\ndeclare_table_target(db, \"Person\", person_schema, primary_key=person_schema.primary_key)","handlingStrategy":"validation","validationCode":"if table_schema is not None:\n    assert primary_key == table_schema.primary_key\nawait falkordb.declare_table_target(db, name, table_schema, primary_key=table_schema.primary_key)","typeGuard":null,"tryCatchPattern":"try:\n    await falkordb.declare_table_target(db, name, table_schema, primary_key=pk)\nexcept ValueError as e:\n    if \"does not match schema's\" in str(e):\n        logging.error(\"Use the schema's primary_key for relationship-endpoint tables: %s\", e)\n    raise","preventionTips":["Always derive the key from table_schema.primary_key when registering referenced tables.","Use the same schema object for the main table and its relationship-endpoint declaration.","Don't hardcode 'id' — pass through the schema or a shared constant."],"tags":["python","falkordb","primary-key","consistency"],"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"}