# pydantic_core._pydantic_core.ValidationError：1 个验证错误（UserCreate）
email
  字段必填 [type=missing, input_value={'name': 'a'}, input_type=dict]

- **ID:** `python/pydantic-field-required-missing`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

输入字典中缺少必填字段 'email'。在 Pydantic v2 中，没有默认值的字段是必填的；键缺失会触发 missing 错误。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   from typing import Optional
from pydantic import BaseModel
class UserCreate(BaseModel):
    email: Optional[str] = None
   ```
2. **** (80% 成功率)
   ```
   from pydantic import BaseModel, Field
class UserCreate(BaseModel):
    email: str = Field(default_factory=lambda: 'unknown@example.com')
   ```

## 无效尝试

- **** — Type checker complains and downstream code gets None where str is expected, causing AttributeError later. (55% 失败率)
- **** — Empty string bypasses required validation and pollutes DB with blank emails. (50% 失败率)
- **** — Silently swallows real data problems; later inserts fail with NOT NULL constraint. (40% 失败率)
