python
install_error
ai_generated
true
pydantic.errors.PydanticUserError: `from_orm` is deprecated; use `model_validate` with `from_attributes=True`
ID: python/fastapi-pydantic-v2-orm-mode
80%Fix Rate
88%Confidence
0Evidence
2024-03-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.x | active | — | — | — |
Root Cause
Pydantic v1 API used with Pydantic v2 installed, typically after upgrading FastAPI.
generic中文
在安装了Pydantic v2的情况下使用了Pydantic v1 API,通常是升级FastAPI后。
Workarounds
-
95% success
class UserOut(BaseModel):\n model_config = ConfigDict(from_attributes=True)\n id: int
-
90% success
UserOut.model_validate(user_obj)
Dead Ends
Common approaches that don't work:
-
70% fail
FastAPI >=0.100 requires pydantic v2; other errors appear.
-
85% fail
orm_mode is a v1 setting; ignored in v2.