skip to Main Content

Following the documentation from Django Postgres DocumentationI added to my settings.py

in settings I set

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'OPTIONS': {
            'service': 'my_service',
            'passfile': '.my_pgpass',
        },
    }
}

Adjacent to settings.py I created pg_service.conf with

[my_service]
host=localhost
user=USER
dbname=NAME
port=5432

and adjacent to that I created mypg_pass

localhost:5432:PostgreSQL 14:postgres:LetMeIn

I am pretty sure I followed the documentation but on python manage.py check I got the following error.

 connection = Database.connect(**conn_params)
  File "C:Usersoliverbasecorrelator2v2correlator2homevenvlibsite-packagespsycopg2__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)django.db.utils.OperationalError: definition of service "my_service" not found

2

Answers


  1. It is not able to find the service, but actually one is not required to use the service at all…

    OP can simply

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': 'NAME', # database name
            'USER': 'USER',
            'PASSWORD': '',
            'HOST': 'localhost',
            'PORT': '5432',
        }
    }
    
    Login or Signup to reply.
  2. Adjacent to settings.py I created pg_service.conf

    That is not where the system looks for it, see the docs

    "By default, the per-user service file is named ~/.pg_service.conf." Where ~ refers to your home directory, not your current directory (and surely doesn’t refer to ‘the same directory where settings.py is located’, since PostgreSQL doesn’t even know what that file is)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search