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.
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',
},
}
Subreddit
Post Details
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/django/comm...