# Pydantic 验证错误：Item 的 name 字段必填。

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

## 根因

Pydantic 模型字段是必填的，但请求中未提供。

## 版本兼容性

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

## 解决方案

1. **Include all required fields in the request body** (95% 成功率)
   ```
   curl -X POST http://localhost:8000/items -H 'Content-Type: application/json' -d '{"name": "item"}'
   ```
2. **Make the field optional with a default** (90% 成功率)
   ```
   class Item(BaseModel):
    name: str = 'default'
   ```

## 无效尝试

- **Sending the field with a null value** — Null is not the same as a missing field; validation still fails. (80% 失败率)
- **Using the wrong field name** — Field names must match exactly. (90% 失败率)
