# sqlalchemy.exc.InvalidRequestError: Could not determine join condition between parent/child tables on relationship User.addresses

- **ID:** `python/sqlalchemy-cannot-determine-join-condition`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

SQLAlchemy cannot automatically infer the foreign key relationship between two models, often due to missing or ambiguous foreign keys.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **Explicitly define the foreign_keys argument in the relationship** (95% success)
   ```
   class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    addresses = relationship('Address', foreign_keys='Address.user_id')
   ```
2. **Use primaryjoin to specify the join condition** (90% success)
   ```
   addresses = relationship('Address', primaryjoin='User.id == Address.user_id')
   ```

## Dead Ends

- **Adding a random foreign key column** — The column may not match the intended relationship, causing incorrect joins. (70% fail)
- **Removing the relationship entirely** — This breaks the ORM association and required functionality. (90% fail)
