I have a postgres database on my localhost I can access without a password
$ psql -d mwt psql (8.4.12) Type "help" for help. mwt=# SELECT * from vatid; id | requester_vatid |... -----+-----------------|... 1719 | IT00766780266 |...
I want to access that database from django. So I put in DATABASES
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'mwt', 'USER': 'shaoran', 'HOST': 'localhost' } }
Since I don't need a password to access my test database I didn't provide any PASSWORD
value in the settings.
$ ./manage.py shell >>> from polls.models import Vatid >>> Vatid.objects.all() connection_factory=connection_factory, async=async) OperationalError: fe_sendauth: no password supplied
I tried using PASSWORD: ''
but I get the same error message. I tried to use PASSWORD: None
but that didn't help either.
I've been searching the django documentation about this but I cannot find anything useful. It is possible to configure django.db.backends.postgresql_psycopg2
to accept empty password?
To establish connection with the PostgreSQL database, make sure that you have installed it properly in your system. Open the PostgreSQL shell prompt and pass details like Server, Database, username, and password. If all the details you have given are appropriate, a connection is established with PostgreSQL database.
Both MySQL and PostgreSQL are supported. You would use psycopg2 to connect to Postgres and e.g. MySQLdb to connect to MySQL. You also have to change the connection string.
The default username for postgres is postgres. (If you are using Advanced Server it is enterprisedb.) On a Mac or Windows, you are able to connect to the default instance by simply hitting enter at the shell or command prompt when trying to run psql and keying in the password.
Surprisingly, the answer is to not specify a host at all. If you do this,
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'mwt', } }
Then psycopg2 will connect using a Unix socket in the same manner as psql
. When you specify a HOST
, psycopg2 will connect with TCP/IP, which requires a password.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With