Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django database connection error

I ran these lines from "python manage.py shell":

from django.db import connection
cursor = connection.cursor()

But got the following error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 306, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 177, in _cursor
    self.connection = Database.connect(**conn_params)
  File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect
    connection_factory=connection_factory, async=async)
OperationalError: FATAL:  role "jay" does not exist

In settings.py I have

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', 
        'NAME': 'mysite',                     
        'USER': '',                     
        'PASSWORD': '',                  
        'HOST': '',                      
        'PORT': '',                     
    }
}

What am I doing wrong here? I installed postgresql and the adapter

like image 350
petabyte Avatar asked Sep 07 '12 11:09

petabyte


1 Answers

FATAL: role "jay" does not exist

Since USER is blank, it's using whatever your local username is (jay), and you haven't created a PostgreSQL user by that name.

Try:

psql -u postgres createuser -P jay

You'll probably have to put the password you enter at the prompt into settings.py, unless your pg_hba.conf is using ident as the auth method.

like image 81
Craig Ringer Avatar answered Nov 04 '22 01:11

Craig Ringer