# pydantic.errors.PydanticUserError: `from_orm`已弃用；请使用`model_validate`并设置`from_attributes=True`

- **ID:** `python/fastapi-pydantic-v2-orm-mode`
- **领域:** python
- **类别:** install_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在安装了Pydantic v2的情况下使用了Pydantic v1 API，通常是升级FastAPI后。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   class UserOut(BaseModel):\n    model_config = ConfigDict(from_attributes=True)\n    id: int
   ```
2. **** (90% 成功率)
   ```
   UserOut.model_validate(user_obj)
   ```

## 无效尝试

- **** — FastAPI >=0.100 requires pydantic v2; other errors appear. (70% 失败率)
- **** — orm_mode is a v1 setting; ignored in v2. (85% 失败率)
