# pydantic.errors.PydanticUserError: `BaseSettings` 已移至 `pydantic-settings` 包。

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

## 根因

项目升级到了 Pydantic v2（FastAPI 0.100+ 要求），但代码仍从 pydantic 导入 BaseSettings。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   pip install pydantic-settings
from pydantic_settings import BaseSettings
   ```
2. **** (85% 成功率)
   ```
   class Settings(BaseSettings):
    model_config = SettingsConfigDict(env_file='.env')
   ```

## 无效尝试

- **** — Conflicts with FastAPI's dependency requirement and breaks other packages. (80% 失败率)
- **** — It's a raised exception, not a warning; import still fails. (90% 失败率)
