# sqlalchemy.exc.AmbiguousForeignKeysError：无法确定父/子表之间的连接条件——存在多个外键路径链接表。请指定 'foreign_keys' 参数。

- **ID:** `python/sqlalchemy-ambiguous-foreign-key`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

两个表之间存在多个外键，未指定显式连接条件。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **Specify 'foreign_keys' argument in relationship.** (95% 成功率)
   ```
   class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    addresses = relationship('Address', foreign_keys='Address.user_id')
   ```
2. **Use primaryjoin explicitly.** (90% 成功率)
   ```
   addresses = relationship('Address', primaryjoin='User.id == Address.user_id')
   ```

## 无效尝试

- **Removing one foreign key constraint from the database.** — Destructive and may break data integrity; not necessary. (50% 失败率)
- **Setting primaryjoin with a string that doesn't match columns.** — String must be a valid SQL expression; typos cause errors. (70% 失败率)
