I am trying to re-deploy my Python Django App on Heroku after the free dyno canceled.
However, I got OperationalError at /catalog/ in Heroku:
connection to server at "127.0.0.1", port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
Exception Location: /app/.heroku/python/lib/python3.10/site-packages/psycopg2/__init__.py, line 122, in connect
I ran the App locally without any issue, and I used this as a reference but not solving my problem. I tried several changes in my settings.py:
ALLOWED_HOSTS = ['.herokuapp.com','127.0.0.1']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'somename',
'USER': 'someuser',
'PASSWORD': 'somepassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
I personally believe the error was caused by those code above, and I had changed PORT
to "8000"
, or used DATABASES['default'] = dj_database_url.config()
, or set ENGINE
to 'django.db.backends.postgresql'
, but those attempts were not working neither.
Since it rans without error locally, so I am wondering what caused the Operational Error appeared?
I would sincerely appreciate all the help since this issue bothered me for few days.
Edit: After multiple tryouts I realized the error was probably caused by dj_database_url
, but the error was not solved yet. Please let me know how to set my DATABASES_URL correctly.