# pydantic_settings.exceptions.SettingsError: 从源 "EnvSettingsSource" 解析字段 "DATABASE_URL" 的值时出错

- **ID:** `python/starlette-uvicorn-invalid-env`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Pydantic BaseSettings 字段期望 URL/int/bool，但环境变量格式错误或为空。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   from pydantic import PostgresDsn
class Settings(BaseSettings):
    database_url: PostgresDsn
   ```
2. **** (95% 成功率)
   ```
   export DATABASE_URL='postgresql://user:pass@localhost:5432/db'
   ```

## 无效尝试

- **** — Downstream code receives None and fails at connect time. (80% 失败率)
- **** — Silently connects to the wrong database. (85% 失败率)
