# django.db.utils.OperationalError: could not connect to server: Connection refused

- **ID:** `python/django-database-connection-timeout`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

数据库服务器未运行或网络不可达

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.2 | active | — | — |
| 4.0 | active | — | — |
| 5.0 | active | — | — |

## Workarounds

1. **检查数据库服务状态** (90% success)
   ```
   systemctl status postgresql 或 service mysql status
   ```
2. **验证数据库配置** (95% success)
   ```
   检查 settings.py 中的 DATABASES 设置，确保主机、端口、用户名、密码正确
   ```

## Dead Ends

- **增加超时时间** — 如果数据库未运行，超时无法解决问题 (70% fail)
- **修改数据库配置为本地连接** — 如果数据库在远程，本地连接无效 (50% fail)
