# 类型错误: 使用Pydantic模型时不允许有多个body参数。

- **ID:** `python/fastapi-multiple-body-params`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

FastAPI路由中定义了多个Pydantic模型作为body参数，但HTTP请求只能有一个body。

## 版本兼容性

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

## 解决方案

1. **将多个模型合并为一个嵌套模型** (95% 成功率)
   ```
   class Item(BaseModel): name: str; class User(BaseModel): username: str; class Combined(BaseModel): item: Item; user: User; @app.post('/create') async def create(data: Combined): return data
   ```
2. **使用Body参数分别标注** (90% 成功率)
   ```
   from fastapi import Body; @app.post('/create') async def create(item: Item = Body(...), user: User = Body(...)): return {'item': item, 'user': user}
   ```

## 无效尝试

- **尝试合并模型但忽略字段冲突** — 合并后字段名冲突。 (60% 失败率)
- **使用多个非模型参数（如str）作为body** — FastAPI会将多个参数视为查询参数。 (70% 失败率)
