# pydantic.errors.PydanticUserError: `orm_mode` 已弃用，请使用 `from_attributes`。

- **ID:** `python/fastapi-pydantic-v1-v2-migration-error`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

为 Pydantic v1 编写的代码（`class Config: orm_mode = True`）在 Pydantic v2 下运行，而 v2 重命名了该设置。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   class UserOut(BaseModel):
    model_config = ConfigDict(from_attributes=True)
    id: int
    name: str
   ```
2. **** (85% 成功率)
   ```
   Run `bump-pydantic` codemod: `pip install bump-pydantic && bump-pydantic .` to auto-migrate.
   ```

## 无效尝试

- **** — FastAPI 0.100+ requires Pydantic v2; pip resolver errors. (90% 失败率)
- **** — Config is ignored; from_orm/validation fails at runtime. (85% 失败率)
