# one() 未找到任何行

- **ID:** `python/sqlalchemy-orm-exc-no-result-found`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

使用 .one() 方法但查询未返回任何行，该方法期望恰好一个结果。

## 版本兼容性

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

## 解决方案

1. **Use one_or_none() with None check** (95% 成功率)
   ```
   Use .one_or_none() and handle None explicitly, e.g., user = session.query(User).filter_by(id=1).one_or_none().
   ```
2. **Use first() method** (85% 成功率)
   ```
   Use .first() if only the first result is needed, but be aware of potential multiple rows.
   ```

## 无效尝试

- **Using scalar() instead** —  (60% 失败率)
- **Assuming default value exists** —  (50% 失败率)
