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 in Python by ana1504.k
• 7,870 points
47 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 by SDeb
• 13,180 points

Related Questions In Python

+1 vote
1 answer

Django not found error

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

answered Jun 24 in Python by Fata
• 1,040 points
36 views
+2 votes
2 answers

Error while printing hello world in python.

You must be trying this command in ...READ MORE

answered Mar 31, 2018 in Python by GandalfDwhite
• 1,320 points
114 views
0 votes
2 answers

Indentation Error in Python

Use tabs instead of spaces. This is ...READ MORE

answered Feb 14 in Python by Shashank
• 1,350 points
94 views
0 votes
1 answer

'Syntax Error: invalid syntax' for no apparent reason

You're missing a close paren in this ...READ MORE

answered Aug 13, 2018 in Python by Priyaj
• 56,900 points
135 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
172 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
• 56,900 points
155 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,180 points
567 views
0 votes
11 answers