Introduction
Upon executing an internal service of a Django-based application, there is an error appear. The message of that error is pointing out that there is no table with a certain name. That table is a necessary in order for the Django-based application to run properly. It is still not clear whether the movement of a single folder of the project where the Django-based application affect it or not. But before discussing on a suitable solution to handle the error message, the following is the actual condition triggering the error message :
-
First of all, there is a folder containing the Django-based application. In this context, it is a folder with the name of ‘myproject’ with the following structure :
C:\python\programming\myproject>tree . Folder PATH listing for volume Windows Volume serial number is 000000AC E003:3593 C:\PYTHON\PROGRAMMING\MYPROJECT ├───app │ └───__pycache__ ├───myproject │ ├───static │ │ └───assets │ │ ├───css │ │ ├───fonts │ │ │ ├───flaticon │ │ │ ├───fontawesome │ │ │ ├───simple-line-icons │ │ │ └───summernote │ │ ├───img │ │ │ ├───banner │ │ │ ├───examples │ │ │ ├───flags │ │ │ ├───production │ │ │ └───slide │ │ ├───js │ │ │ ├───core │ │ │ └───plugin │ │ │ ├───bootstrap-notify │ │ │ ├───chart-circle │ │ │ ├───chart.js │ │ │ ├───datatables │ │ │ ├───jquery-scrollbar │ │ │ ├───jquery-ui-1.12.1.custom │ │ │ ├───jquery-ui-touch-punch │ │ │ ├───jquery.sparkline │ │ │ ├───jqvmap │ │ │ │ └───maps │ │ │ │ └───continents │ │ │ ├───sweetalert │ │ │ └───webfont │ │ └───sass │ │ └───atlantis │ │ ├───components │ │ └───plugins │ ├───staticfiles │ ├───templates │ │ └───app │ └───__pycache__ ├───media │ ├───banner │ └───thumb └───staticfiles C:\python\programming\myproject>
-
After trying to run the application, the error appear as in the following :
django.db.utils.OperationalError: no such table: banner_slide
The database connection configuration is pointing to the default database engine setting. It is using the normal and the default ‘sqlite3’ database engine. The configuration is available in the following entry exist in the ‘settings.py’ file :
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME' : 'db.sqlite3', } }
-
So, in this context, inside the ‘db.sqlite3’ file there is no longer any table with the name as mentioned before in order for the application to start.
Solution
There are several steps for starting the application properly without having to deal with the error. The following are the steps for solving the problem as a solution :
-
First of all, checking the migration status of the Django-based application by executing the following command :
C:\python\programming\myproject>python manage.py makemigrations No changes detected C:\python\programming\myproject>
-
Since there is no changes available in term of the migration script nor the model, just try to to execute the migration script once more by executing the following command :
(env) C:\python\programming\myproject> python manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: No migrations to apply. (env) C:\python\programming\myproject>
-
Last but not least, executing a command just to synchronize the database since there is a missing table from it according to the Django-based application upon its execution. The following command is a command for synchronizing the database :
(env) C:\python\programming\myproject> python manage.py migrate --run-syncdb Operations to perform: Synchronize unmigrated apps: app, banner Apply all migrations: admin, auth, contenttypes, sessions Synchronizing apps without migrations: Creating tables... ... Creating table banner_category Creating table banner_tag ... Running Running migrations: No migrations to apply. (env) C:\python\programming\myproject>
-
Finally, just re-execute the application and access it once more. If there are no more errors exist, the application will appear normally.