# PydanticImportError: `BaseSettings` 已移至 `pydantic-settings` 包。详情见 https://docs.pydantic.dev/2.0/migration/。

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

## 根因

为 Pydantic v1 编写的代码从 pydantic 导入 BaseSettings，但 Pydantic v2 将其移至独立包。

## 版本兼容性

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

## 解决方案

1. **** (93% 成功率)
   ```
   pip install pydantic-settings; from pydantic_settings import BaseSettings
   ```
2. **** (85% 成功率)
   ```
   Set model_config = SettingsConfigDict(env_file='.env') instead of class Config
   ```

## 无效尝试

- **** — FastAPI latest requires v2 features; downgrade cascades. (60% 失败率)
- **** — Import still fails at class definition time. (80% 失败率)
