# KeyError: 'DATABASE_URL'

- **ID:** `python/flask-config-key-missing`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Flask配置字典中缺少必需的配置键

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **在配置加载时设置默认值** (90% success)
   ```
   app.config.setdefault('DATABASE_URL', 'sqlite:///default.db')
   ```
2. **使用环境变量并设置默认** (95% success)
   ```
   import os
app.config['DATABASE_URL'] = os.environ.get('DATABASE_URL', 'sqlite:///dev.db')
   ```

## Dead Ends

- **使用默认值但未检查环境变量** — 默认值可能不适用于生产环境 (50% fail)
- **在代码中硬编码配置值** — 硬编码不利于配置管理 (40% fail)
