python
network_error
ai_generated
true
django.db.utils.OperationalError: connection refused - check hostname and port
ID: python/django-database-connection-refused
80%Fix Rate
87%Confidence
0Evidence
2024-06-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Database server is not running or connection parameters are incorrect.
generic中文
数据库服务器未运行或连接参数不正确。
Workarounds
-
80% success
Start database service: sudo systemctl start postgresql (or mysql)
-
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
Common approaches that don't work:
-
50% fail
Changing database engine in settings without restarting server won't take effect.
-
30% fail
Using localhost instead of 127.0.0.1 can cause IPv6 resolution issues.