Django deploy error on Heroku App "connection to server at "", port 5432 failed: Connection refused"

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 "", 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/, 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


    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'somename',
        'USER': 'someuser',
        'PASSWORD': 'somepassword',
        'HOST': '',
        'PORT': '5432',

import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=500)

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.

Back to Top