python
config_error
ai_generated
true
pydantic.errors.PydanticUserError: `Config` and `fields` are deprecated in Pydantic V2. Use `model_config` and `Field` instead. See https://docs.pydantic.dev/2.0/migration/
ID: python/pydantic-config-and-fields-deprecated
80%Fix Rate
90%Confidence
0Evidence
2024-01-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.x | active | — | — | — |
Root Cause
A v1-style inner class Config or fields dict was used in a model under Pydantic v2.
generic中文
在 Pydantic v2 的模型中使用了 v1 风格的内嵌 Config 类或 fields 字典。
Workarounds
-
90% success
from pydantic import BaseModel, ConfigDict class M(BaseModel): model_config = ConfigDict(orm_mode=True) # was class Config: orm_mode = True x: int -
85% success
pip install bump-pydantic bump-pydantic ./src
Dead Ends
Common approaches that don't work:
-
80% fail
No such switch exists; pydantic 2.x always rejects v1 config.
-
60% fail
Blocks upgrades of FastAPI and other deps that require v2.
-
70% fail
The error is raised at class definition time, not import time, and cannot be caught usefully.