1

I use PostreSQL and Django 1.8 in my app. I have an error:

django.db.utils.OperationalError: could not translate host name "postgres" to address: nodename nor servname provided, or not known

but I cannot find a please where host name "postgres" is set, because I have set host name to localhost.

DATABASE_USER = MY_DATABASE_USER = admin
DATABASE_HOST = MY_DATABASE_HOST = localhost

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'default_db',
        'USER': os.getenv('DATABASE_USER', ''),
        'PASSWORD': os.getenv('DATABASE_PASSWORD', ''),
        'HOST': os.getenv('DATABASE_HOST', ''),
        'PORT': '5432',
    },
    'my_db': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.getenv('MY_DATABASE_NAME', 'my_dev'),
        'USER': os.getenv('MY_DATABASE_USER', os.getenv('DATABASE_USER', 'admin')),
        'PASSWORD': os.getenv('MY_DATABASE_PASSWORD', os.getenv('DATABASE_PASSWORD', '')),
        'HOST': os.getenv('MY_DATABASE_HOST', os.getenv('DATABASE_HOST', '')),
        'PORT': '5432',
    }
}

Can I fix that error?

v18o
  • 1,237
  • 2
  • 15
  • 25
  • You're not using the constants you've defined at the top, you're reading the settings from the environment. –  Nov 23 '17 at 22:29
  • @MartinBroadhurst and I define them the same in env. – v18o Nov 23 '17 at 22:34
  • Are you using Docker? –  Nov 23 '17 at 22:37
  • @MartinBroadhurst project that I run was configured for Docker, but I run it locally. With locally installed and populated PostgreSQL and Django app in virtualenv. – v18o Nov 23 '17 at 22:57

0 Answers0