pythondjangoapachepostgresqlgithub

Steps to Troubleshoot "django.db.utils.ProgrammingError: permission denied for relation django_migrations"


What are some basic steps for troubleshooting and narrowing down the cause of the Django error:

django.db.utils.ProgrammingError: permission denied for relation django_migrations

I'm getting this message after what was initially a stable production server but has since had some changes to several aspects of Django, Postgres, Apache, and a pull from Github. In addition, it has been some time since those changes were made. I don't recall or can't track every change that may be causing the problem.

I get the message when I run python manage.py runserver or any other python manage.py ... command except python manage.py check, which states the system is good.


Solution

  • I was able to solve my issue based on instructions from this question. Basically, postgres privileges needed to be re-granted to the db user. In my case, that was the user I had setup in the virtual environment settings file. Run the following from the commandline (or within postgres) where mydatabase and dbuser should be your own database and user names:

    psql mydatabase -c "GRANT ALL ON ALL TABLES IN SCHEMA public to dbuser;"
    psql mydatabase -c "GRANT ALL ON ALL SEQUENCES IN SCHEMA public to dbuser;"
    psql mydatabase -c "GRANT ALL ON ALL FUNCTIONS IN SCHEMA public to dbuser;"