0

Switching from user "postgres", I created a new Postgres user and changed my Django project to make use of this new user / credentials:

sudo -u postgres -i
psql -c "CREATE USER foo WITH PASSWORD 'xxxxxxxxxxxx' CREATEDB;"
psql -c "GRANT ALL PRIVILEGES ON DATABASE bar TO foo;"

In settings for Django:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'bar',
        'USER': 'foo',
        'PASSWORD': 'xxxxxxxxxxxx',
        'HOST': 'localhost',
        'ATOMIC_REQUESTS': True
    }
}

But I get the error when using "python manage.py runserver":

django.db.utils.ProgrammingError: permission denied for relation django_migrations
gornvix
  • 3,154
  • 6
  • 35
  • 74
  • And you ran `python manage.py migrate`? Did it give the same error? – csinchok Oct 03 '16 at 19:29
  • @PopcornArsonist yes, the exact same error. Although I don't need to run "migrate" as the database is already up to date with the migrations. This is not a new installation, previously I was using user "postgres". – gornvix Oct 03 '16 at 19:34
  • 1
    I found another question that seems to be related to this issue. Maybe try the answer from that: http://stackoverflow.com/a/12236582/931098 (just the `GRANT` steps, of course) – csinchok Oct 03 '16 at 19:37
  • Have you added the user to the postgres `pg_hba.conf`? – Timmy O'Mahony Oct 03 '16 at 19:44
  • @PopcornArsonist yes, those GRANT steps solved the problem. Do you know if I also still need: psql -c "GRANT ALL PRIVILEGES ON DATABASE bar TO foo;" ? – gornvix Oct 03 '16 at 20:09
  • 1
    Yes, you probably need that in order to create new tables. – csinchok Oct 03 '16 at 21:24
  • Possible duplicate of [Django: permission denied when trying to access database after restore (migration)](http://stackoverflow.com/questions/12233046/django-permission-denied-when-trying-to-access-database-after-restore-migratio) – csinchok Oct 03 '16 at 21:24

0 Answers0