# pydantic.errors.PydanticUserError：Pydantic V2 已弃用 `Config` 和 `fields`。请改用 `model_config` 和 `Field`。参见 https://docs.pydantic.dev/2.0/migration/

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

## 根因

在 Pydantic v2 的模型中使用了 v1 风格的内嵌 Config 类或 fields 字典。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   from pydantic import BaseModel, ConfigDict
class M(BaseModel):
    model_config = ConfigDict(orm_mode=True)  # was class Config: orm_mode = True
    x: int
   ```
2. **** (85% 成功率)
   ```
   pip install bump-pydantic
bump-pydantic ./src
   ```

## 无效尝试

- **** — No such switch exists; pydantic 2.x always rejects v1 config. (80% 失败率)
- **** — Blocks upgrades of FastAPI and other deps that require v2. (60% 失败率)
- **** — The error is raised at class definition time, not import time, and cannot be caught usefully. (70% 失败率)
