# pydantic.errors.ConfigError: 'extra' 必须是字符串或字典

- **ID:** `python/pydantic-config-extra-forbid`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在 Pydantic v2 中，'extra' 配置选项只接受特定字符串值（'allow'、'ignore'、'forbid'）或字典，不接受布尔值或任意字符串。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Set extra='forbid' or 'allow' in model config: class Model(BaseModel): model_config = ConfigDict(extra='forbid')
   ```
2. **** (85% 成功率)
   ```
   Use a dict to customize extra fields: model_config = ConfigDict(extra={'field': 'value'})
   ```

## 无效尝试

- **** — Boolean values are not valid for 'extra' in v2; it requires string or dict, leading to ConfigError. (80% 失败率)
- **** — 'extra' does not accept a list; it must be a string or dict, so this raises ConfigError. (70% 失败率)
