How to Solve Error Message OperationalError at /admin/login no such table: auth_user upon executing Django Application

Posted on

Introduction

This article is showing on how to solve an error message. It appear when accessing or executing a Django-based application. Precisely, it is when accessing the admin page. Generally, the URL for the admin page exist in ‘localhost:8000/admin’. It is available after running an internal Django-based application service running locally at port 8000. The error message itself has a specific error message as follows :

no such table: auth_user

The following is the image of the error message showing upon accessing the ‘localhost:8000/admin’ address :

How to Solve Error Message no such table: auth_user upon executing Django Application
How to Solve Error Message no such table: auth_user upon executing Django Application

 

Solution

Upon running the internal server of the Django-based application, there is an information giving a clue upon the non-existence of the auth_user table. It exist as follows :

(env) C:\python\programming\myproject>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
October 11, 2021 - 22:12:25
Django version 3.2.6, using settings 'core.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

The error message which is the main focus for the hinting the information to solve the problem is in the following one :

Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them.

It is because the step to perform migration process is not yet there. So, the ‘auth_user’ table is also not available. By executing the migration process, it will generate the important table including ‘auth_user’ to be able to access the admin page of the Django-based application. Just execute it as follows :

(env) C:\python\programming\myproject>python manage.py makemigrations
No changes detected

(env) C:\python\programming\myproject>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying auth.0010_alter_group_name_max_length... OK
Applying auth.0011_update_proxy_permissions... OK
Applying auth.0012_alter_user_first_name_max_length... OK
Applying sessions.0001_initial... OK

(env) C:\python\programming\myproject>

After successfully performing the migration process, just execute and access the admin again once more.

Leave a Reply