What are some basic steps for troubleshooting and narrowing down the cause for the \"django.db.utils.ProgrammingError: permission denied for relation django_migrations\" err
As mentioned by @user3062149, this is likely caused by attempting to migrate a database table for which Django's psycopg2 user is not the table owner. For instance, if you have in your project's settings.py
DATABASES = {
'default': {
'USER': 'my_username',
# ...
You will need to check that the table involved in the Django migration is owned by my_username. To do this in psql, you can use SELECT * FROM pg_tables ORDER BY tableowner;. This uses the view pg_tables, which "provides access to useful information about each table in the database." pg_tables is a part of Postgres' system catalogs, the place where a relational database management system stores schema metadata.
Say that the table in question is owned by other_username (not my_username).
To update the owner, you then need to call psql with --username=other_username, then change the owner:
ALTER TABLE public. OWNER TO my_username;