How to Solve Error Message ProgrammingError at web page permission denied for table table_name when running Django Application

Posted on

Introduction

Another article showing how to solve a specific error message in the execution of a running Django application exist as the content. So, there is an error message appear at the web page of the Django application web as soon as the access execution. After accessing the specific URL of the running Django application using a web browser, the error appear in the web page. The following is the error message appear in that page :

ProgrammingError at /login/

permission denied for table auth_user

Request Method: POST
Request URL: http://localhost:8000/login/
Django Version: 4.0.2
Exception Type: ProgrammingError
Exception Value:

permission denied for table auth_user

Exception Location: C:\repository\apps\env\lib\site-packages\django\db\backends\utils.py, line 85, in _execute
Python Executable: C:\repository\apps\env\Scripts\python.exe
Python Version: 3.10.5
Python Path:

['C:\\repository\\apps',
'C:\\python\\python310\\python310.zip',
'C:\\python\\python310\\DLLs',
'C:\\python\\python310\\lib',
'C:\\python\\python310',
'C:\\repository\\apps\\env',
'C:\\repository\\apps\\env\\lib\\site-packages',
'C:\\repository\\apps\\env\\lib\\site-packages\\win32',
'C:\\repository\\apps\\env\\lib\\site-packages\\win32\\lib',
'C:\\repository\\apps\\env\\lib\\site-packages\\Pythonwin']

How to Solve Error Message ProgrammingError at web page permission denied for table table_name

In this case, there is a specific error which is appear where the main trigger is not directly because of the application. Actually, the main trigger is the database where there is an error in the permission of the table. So, the Django application need to access a certain table in PostgreSQL database. It exist as part of the source code in the Django application. It is obvious as it exist in part of the error message. The error message is giving hint on the error message as in the following line :

permission denied for table auth_user

Using the assumption of the error is actually reside in the PostgreSQL database which is specifically point out the error message, below is the actual step for solving the error message :

  1. As usual, since the solution needs a command execution, just start or run any command line interface available in the operating system.

  2. Next, after running the command line interface, just access the PostgreSQL command console as follows :

    C:\>psql -Upostgres
    Password for user postgres:
    psql (14.2)
    WARNING: Console code page (437) differs from Windows code page (1252)
    8-bit characters might not work correctly. See psql reference
    page "Notes for Windows users" for details.
    Type "help" for help.
    
    postgres=#
    
  3. Following after, just type the command for connecting to the database where the actual table exist as it exist below :

    postgres=# \c db_apps;
    You are now connected to database "db_apps" as user "postgres".
    db_apps=#
    
  4. Actually, granting all privileges to the database does not directly solving the problem as the continuation of the previous. There must be a direct granting process to each one of those tables. It is exist in an article in this link. Next step, just make sure the table where there error message of ‘permission denied’ exist. Below is the execution to do it :

    db_apps=# \dt
                                 List of relations
     Schema |                     Name                      | Type  |  Owner
    --------+-----------------------------------------------+-------+----------
     public | auth_group                                    | table | postgres
     public | auth_group_permissions                        | table | postgres
     public | auth_permission                               | table | postgres
     public | auth_user                                     | table | postgres
     public | auth_user_groups                              | table | postgres
     public | auth_user_user_permissions                    | table | postgres
     public | django_admin_log                              | table | postgres
     public | django_content_type                           | table | postgres
     public | django_migrations                             | table | postgres
     public | django_session                                | table | postgres
     ...
    (56 rows)
    
    -- More  --
    
  5. At once, after finding the correct table, just execute the following command to grant permission for access table.

    db_apps=# grant all privileges on table auth_user to db_user;
    GRANT
    db_apps=#
    
  6. Last but not least, try to execute and access the Django application once more. If there are no further error appear, the page will be accessed properly.

Leave a Reply