# django.db.utils.OperationalError: could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

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

## Root Cause

PostgreSQL数据库未启动或连接配置错误

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   sudo service postgresql start 或 systemctl start postgresql
   ```
2. **** (85% success)
   ```
   确保DATABASES设置中的NAME、USER、PASSWORD正确
   ```

## Dead Ends

- **** — 如果数据库未启动，更改主机地址无效 (80% fail)
- **** — 可能影响生产环境兼容性 (50% fail)
