Reputation: 227
Setting up a Django project but I am getting a warning about setting up postgres
as shown in the title, but I am unsure what this means.
Full warning message:
RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': could not translate host name "postgres" to address: Unknown host
And here is how I define postgres
in my settings.py
:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": os.environ.get("DB_NAME", "dbname"),
"USER": os.environ.get("DB_USER", "dbuser"),
"PASSWORD": os.environ.get("DB_PASSWORD", "dbpassword"),
"HOST": os.environ.get("DB_HOST", "postgres"),
"PORT": os.environ.get("DB_PORT", "5432"),
}
}
Would it possible for someone to walk me through what is going wrong here? I have no idea.
Upvotes: 2
Views: 17865
Reputation: 1296
In order to use django with postgresql you need a reachable postgresql server.
You can install and run it locally : https://www.postgresql.org/download/
Then you postgresql server will be reachable on your localhost interface. This DB_HOST config variable represent the address where your django server should contact your postgresql server.
So you can change the default value of your DB_HOST environment variable from "postgres" to "localhost", or directly set it into your environment (using a .env file for example)
Upvotes: 2