I'm running into a strange issue when resetting my database. A multiple choice field in a form is throwing exception
Unhandled exception in thread started by .wrapper at 0x7f59df160510> Traceback (most recent call last): File "/home/abdullah/PycharmVirtualEnvs/venv/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/home/abdullah/PycharmVirtualEnvs/venv/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 337, in execute return Database.Cursor.execute(self, query, params) sqlite3.OperationalError: no such table: app1_semester The above exception was the direct cause of the following exception: Traceback (most recent call last): ...... File "/home/abdullah/PycharmProjects/langs-dept/project1/app1/urls.py", line 3, in from . import views File "/home/abdullah/PycharmProjects/langs-dept/project1/app1/views.py", line 10, in from . import models, forms File "/home/abdullah/PycharmProjects/langs-dept/project1/app1/forms.py", line 11, in class AddAssignmentForm(forms.Form): File "/home/abdullah/PycharmProjects/langs-dept/project1/app1/forms.py", line 14, in AddAssignmentForm queryset=models.AssignmentType.get_assignment_types(), File "/home/abdullah/PycharmProjects/langs-dept/project1/app1/models.py", line 180, in get_assignment_types return AssignmentType.objects.filter(semester=Semester.get_current_semester()) File "/home/abdullah/PycharmProjects/langs-dept/project1/app1/models.py", line 157, in get_current_semester return semester.first() if semester else None File "/home/abdullah/PycharmVirtualEnvs/venv/lib/python3.5/site-packages/django/db/models/query.py", line 260, in __bool__ self._fetch_all() File "/home/abdullah/PycharmVirtualEnvs/venv/lib/python3.5/site-packages/django/db/models/query.py", line 1087, in _fetch_all self._result_cache = list(self.iterator()) File "/home/abdullah/PycharmVirtualEnvs/venv/lib/python3.5/site-packages/django/db/models/query.py", line 54, in __iter__ results = compiler.execute_sql() File "/home/abdullah/PycharmVirtualEnvs/venv/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 835, in execute_sql cursor.execute(sql, params) File "/home/abdullah/PycharmVirtualEnvs/venv/lib/python3.5/site-packages/django/db/backends/utils.py", line 79, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/home/abdullah/PycharmVirtualEnvs/venv/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/home/abdullah/PycharmVirtualEnvs/venv/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/home/abdullah/PycharmVirtualEnvs/venv/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise raise value.with_traceback(tb) File "/home/abdullah/PycharmVirtualEnvs/venv/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/home/abdullah/PycharmVirtualEnvs/venv/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 337, in execute return Database.Cursor.execute(self, query, params) django.db.utils.OperationalError: no such table: app1_semester
If I comment below piece of code in forms.py, everything is working fine.
class AddAssignmentForm(forms.Form):
assignments = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple(),queryset=models.AssignmentType.get_assignment_types(),required=False)
The method get_assignment_types() is a static method returning some list of values
models.py
@staticmethod
def get_assignment_types():
return AssignmentType.objects.filter()
I can comment that line and do python manage.py makemigrations, but I wonder what is wrong ? Can someone shed some light?