{
  "id": "python/sqlalchemy-cannot-determine-join-condition",
  "signature": "sqlalchemy.exc.InvalidRequestError: Could not determine join condition between parent/child tables on relationship User.addresses",
  "signature_zh": "sqlalchemy.exc.InvalidRequestError: 无法确定父/子表之间的连接条件，关系 User.addresses",
  "regex": "sqlalchemy\\.exc\\.InvalidRequestError:\\ Could\\ not\\ determine\\ join\\ condition\\ between\\ parent/child\\ tables\\ on\\ relationship\\ User\\.addresses",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "SQLAlchemy cannot automatically infer the foreign key relationship between two models, often due to missing or ambiguous foreign keys.",
  "root_cause_type": "generic",
  "root_cause_zh": "SQLAlchemy 无法自动推断两个模型之间的外键关系，通常是由于缺少或模糊的外键。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding a random foreign key column",
      "why_fails": "The column may not match the intended relationship, causing incorrect joins.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Removing the relationship entirely",
      "why_fails": "This breaks the ORM association and required functionality.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Explicitly define the foreign_keys argument in the relationship",
      "success_rate": 0.95,
      "how": "class User(Base):\n    __tablename__ = 'users'\n    id = Column(Integer, primary_key=True)\n    addresses = relationship('Address', foreign_keys='Address.user_id')",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use primaryjoin to specify the join condition",
      "success_rate": 0.9,
      "how": "addresses = relationship('Address', primaryjoin='User.id == Address.user_id')",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}