python
module_error
ai_generated
true
pydantic.errors.PydanticUserError: `BaseSettings` has been moved to the `pydantic-settings` package.
ID: python/fastapi-pydantic-v1-v2-incompat
80%Fix Rate
89%Confidence
0Evidence
2024-02-28First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.x | active | — | — | — |
Root Cause
Project upgraded to Pydantic v2 (required by FastAPI 0.100+) but code still imports BaseSettings from pydantic.
generic中文
项目升级到了 Pydantic v2(FastAPI 0.100+ 要求),但代码仍从 pydantic 导入 BaseSettings。
Workarounds
-
95% success
pip install pydantic-settings from pydantic_settings import BaseSettings
-
85% success
class Settings(BaseSettings): model_config = SettingsConfigDict(env_file='.env')
Dead Ends
Common approaches that don't work:
-
80% fail
Conflicts with FastAPI's dependency requirement and breaks other packages.
-
90% fail
It's a raised exception, not a warning; import still fails.