I have a Django project and I use a local postgresql database and it goes perfectly with the psycopg2 module, now, I put an external database and when I do a migrate it gives the following error.
django.db.utils.OperationalError: FATAL: no pg_hba.conf entry for host "local-IP", user "postgres", database "chewbacca_db", SSL on
FATAL: no pg_hba.conf entry for host "local-IP", user "postgres", database "my_db", SSL off
and in my django project I have it like this... as always
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'my_db',
'USER': 'postgres',
'PASSWORD': 'password',
'HOST': 'external-server-IP',
'PORT': '5432'
}
}
I don't understand why I get the IP address of the local server in the error... if there isn't that IP anywhere in settings.py.
SOLUTION:
The postgresql.conf file has been edited, changing listenaddresses='localhost'
to listenaddresses='*'
and in the pg_hba.conf file it has been added to the IPv4 section, immediately host all all 0.0.0.0/0 md5
afterwards a restart of the sudo service postgresql restart service is performed and voila.
Several things need to be checked: