# sqlalchemy.exc.AmbiguousForeignKeysError: 无法确定 User.posts 关系上父/子表之间的连接条件 - 存在多条连接两表的外键路径。

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

## 根因

两个表之间存在多个外键，导致 SQLAlchemy 无法推断关系使用哪个外键。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   posts = relationship('Post', foreign_keys='Post.author_id')
   ```
2. **** (90% 成功率)
   ```
   posts = relationship('Post', primaryjoin='User.id == Post.author_id')
   ```

## 无效尝试

- **** — Breaks the data model that intentionally needs both. (90% 失败率)
- **** — Does not resolve join ambiguity. (85% 失败率)
