# FastAPI请求验证错误：缺少必填字段 (类型=值错误.缺失)

- **ID:** `python/fastapi-validation-error-missing-field`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

请求体或查询参数中缺少必填字段。

## 版本兼容性

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

## 解决方案

1. **Add the missing field in the request body or query parameters with a valid value.** (95% 成功率)
   ```
   {"name": "John", "age": 30}  # Include all required fields
   ```
2. **Modify the Pydantic model to make the field optional with a default value.** (85% 成功率)
   ```
   from pydantic import BaseModel
class Item(BaseModel):
    name: str = None  # Optional with default
   ```

## 无效尝试

- **Setting the field as Optional in the Pydantic model but not providing a default value.** — Optional without default still requires the field in validation; it only allows None. (60% 失败率)
- **Ignoring the error and sending the same request again without changes.** — The request is still malformed; the error will persist. (95% 失败率)
