Django Postgresql syncdb error

0 votes
When I run python manage.py syncdb, I get the following error:

OperationalError: could not translate host name "localhost" to address: nodename nor servname provided, or not known
 

my settings.py file consist of:

if "IS_STAGING" in os.environ or "IS_PRODUCTION" in os.environ:
    import dj_database_url
    DATABASES = {'default':dj_database_url.config(default='postgres://localhost')}
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
            'NAME': 'test',                      # Or path to database file if using sqlite3.
            # The following settings are not used with sqlite3:
            'USER': 'test',
            'PASSWORD': 'test',
            'HOST': 'localhost',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
            'PORT': '',                      # Set to empty string for default.
        }
    }

Can anyone help me solve this error?
May 27, 2019 in Python by ana1504.k
• 7,910 points
1,588 views

1 answer to this question.

0 votes
If you're trying to connect to a local database, your best bet is to leave the host as an empty string:

'HOST': ''

If that doesn't work, the following should:

'HOST': '127.0.0.1'
answered May 27, 2019 by SDeb
• 13,300 points

Related Questions In Python

0 votes
1 answer

Error:Django connection to PostgreSQL: “Peer authentication failed”

Hello @kartik, My settings.py did not have a ...READ MORE

answered Aug 12, 2020 in Python by Niroj
• 82,840 points
2,094 views
+1 vote
1 answer

Django not found error

Before installing Django make sure you have ...READ MORE

answered Jun 24, 2019 in Python by Fata
• 1,050 points
2,663 views
0 votes
1 answer

Error: port is already in use of Django Server

Hii @kartik, Just type sudo fuser -k 8000/tcp. This ...READ MORE

answered May 6, 2020 in Python by Niroj
• 82,840 points
15,508 views
0 votes
1 answer

Error:django MultiValueDictKeyError

Hello @kartik, Use the MultiValueDict's get method. This is also ...READ MORE

answered May 20, 2020 in Python by Niroj
• 82,840 points
35,785 views
0 votes
1 answer

how to download and install Django rest framework?

To install Django, you can simply open ...READ MORE

answered Apr 24, 2018 in Python by Christine
• 15,790 points
1,966 views
0 votes
1 answer
0 votes
1 answer

Host not allowed

Go to your project directory cd project cd project ALLOWED_HOSTS ...READ MORE

answered Aug 9, 2018 in AWS by Priyaj
• 58,020 points
1,742 views
0 votes
1 answer

Key error in Python

A KeyError occurs when the Key doesn't ...READ MORE

answered Sep 20, 2018 in Python by SDeb
• 13,300 points
1,476 views
0 votes
11 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP