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?
Check your
pg_hba.confto allow connection fromlocalhostby usershaoran, then either provide the password ofshaoranin Django settings or trust the user inpg_hba.confThe fact that you could connect through
psqlis becausepsql -d mwtuses some default connection values which are set as trusted inpg_hba.conf. For example, on my machine, the default host islocal socketinstead oflocalhost