Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Error When Connecting To Postgres Database From A Django App
Post Body

I am not sure if this is the right forum for this question, but since it is Django related, I will go ahead and ask here.

I have created a simple Django app which has been deployed in Pythonanywhere using a free server. I have a multi-db setup where the default database uses MySQL which is available in Pythonanywhere and I also have a second database which uses Postgres and is deployed in Heroku which is also a paid add on. This is the first time I am trying a multi-db setup. I am using the latest version of Django (V3.0.5).

The problem is, everything works fine when I try to connect to Postgres when using the development server from my system. But when I try to connect to it after the app is deployed live, I get a server error. The server log from Pythonanywhere shows the below message. Can anyone guide me on what this error means and how can I go about fixing it?

Note - I have masked the Host and IP Address in the below error as the credentials belong to our production db.

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

Below is how my settings.py file looks like for reference. Note that I have masked the production db credentials.

if DEBUG:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        },
        'postgres': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': 'NAME',
            'USER': 'USER',
            'PASSWORD': 'PASSWORD',
            'HOST': 'HOST',
            'PORT': '5432',
        },
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'NAME',
            'USER': 'USER',
            'PASSWORD': 'PASSWORD',
            'HOST': 'HOST',
            'PORT': '3306',
            'OPTIONS': {
                'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
            }
        },
        'postgres': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': 'NAME',
            'USER': 'USER',
            'PASSWORD': 'PASSWORD',
            'HOST': 'HOST',
            'PORT': '5432',
        },
    }

Author
User Disabled
Account Strength
0%
Disabled 4 months ago
Account Age
5 years
Verified Email
Yes
Verified Flair
No
Total Karma
6,531
Link Karma
663
Comment Karma
5,737
Profile updated: 4 days ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago