How to Solve Error Message no such table: django_session

Posted on

This article mainly inform about how to solve an error message. That error message itself appear in Django-based web application execution. After creating a Django-based web project using a certain command and execute it directly, the error appears. It appear as soon as the action for accessing an address with the URL of ‘localhost:8000/admin’ is done. The following is the appearance of the error in an image :

How to Solve Error Message no such table: django_session
How to Solve Error Message no such table: django_session

Basically, the error message is “no such table: django_session”. Basically, the error message informing that there is no table with the name of ‘django_session’. In order to solve the error, the solution is very simple. Just execute the command for migrating the model definition of the Django-based web application. The following is the command execution to migrate the model definition into the associated tables and database :

(myenv) c:\python-win\project>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 sessions.0001_initial... OK

(myenv) c:\python-win\project>

After successfully execute the above command for migrating the database, just access the address of the application again. The following image will appear :

How to Solve Error Message no such table: django_session
How to Solve Error Message no such table: django_session

It means, the table with the name of django_session is available after the execution of the above command. The table exist in the database where the main definition exist in the file with the name of ‘settings.py’. It exist as follows :

C:\Program Files\PostgreSQL\12\bin>psql -Upostgres
Password for user postgres:
psql (12.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=# \l
                                                 List of databases
   Name    |  Owner   | Encoding |          Collate           |           Ctype            |   Access privileges
-----------+----------+----------+----------------------------+----------------------------+-----------------------
 db_app    | postgres | UTF8     | English_United States.1252 | English_United States.1252 |
 postgres  | postgres | UTF8     | English_United States.1252 | English_United States.1252 |
 template0 | postgres | UTF8     | English_United States.1252 | English_United States.1252 | =c/postgres          +
           |          |          |                            |                            | postgres=CTc/postgres
 template1 | postgres | UTF8     | English_United States.1252 | English_United States.1252 | =c/postgres          +
           |          |          |                            |                            | postgres=CTc/postgres
(4 rows)


postgres=# \c db_app
You are now connected to database "db_app" as user "postgres".
db_app=# \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
(10 rows)


db_app=#

At the end of the last row of the above command execution, there is table with the name of ‘django_session’.

Leave a Reply