# django.db.utils.OperationalError: connection refused - check hostname and port

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

## Root Cause

Database server is not running or connection parameters are incorrect.

## Version Compatibility

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

## Workarounds

1. **** (80% success)
   ```
   Start database service: sudo systemctl start postgresql (or mysql)
   ```
2. **** (90% success)
   ```
   Verify settings: DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql', 'NAME': 'mydb', 'USER': 'user', 'PASSWORD': 'pass', 'HOST': '127.0.0.1', 'PORT': '5432'}}
   ```

## Dead Ends

- **** — Changing database engine in settings without restarting server won't take effect. (50% fail)
- **** — Using localhost instead of 127.0.0.1 can cause IPv6 resolution issues. (30% fail)
