I’ve successfully created a Django project in Pycharm to talk to the default Sqlite3. But now I’d like to switch to Postgress. I have the following in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'jdbc:postgresql://localhost:5432/postgres',
'PORT': '5432'
}
}
But I get this error when trying to run
django.db.utils.OperationalError: could not translate host name "jdbc:postgresql://localhost:5432/postgres" to address: Name or service not known
I get the same error when trying to run migrate
, which I assume is necessary to create the tables
2
Answers
HOST should just be "localhost".
Unrequested advice: you probably don’t want Django creating tables in the Postgres database. Better to create another database and point Django to that.
The purpose of the DATABASE dictionary is to pass all the specifics to their respective keys as required. There is no need to pass along the connection string here like this. Passing just
localhost
here should be enough.