本文介绍了OperationalError:删除数据库和迁移后没有这样的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我删除了db和所有用于重置数据库的迁移.但是删除后,当我尝试运行Makemigrations显示错误
I deleted db and all migrations for resetting my database. But after the deletion when I tried to runMakemigrations it is showing the error that
我有一个名为Student_app的应用其中有一个名为Grade的模型
I have an app named student_appAnd in that there is a model with name Grade
这是完整的错误
Traceback (most recent call last):
File "/home/ajit/.local/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/ajit/.local/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: student_app_grade
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/ajit/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/ajit/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ajit/.local/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ajit/.local/lib/python3.5/site-packages/django/core/management/base.py", line 342, in execute
self.check()
File "/home/ajit/.local/lib/python3.5/site-packages/django/core/management/base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "/home/ajit/.local/lib/python3.5/site-packages/django/core/management/base.py", line 361, in _run_checks
return checks.run_checks(**kwargs)
File "/home/ajit/.local/lib/python3.5/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/ajit/.local/lib/python3.5/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/home/ajit/.local/lib/python3.5/site-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/home/ajit/.local/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/ajit/.local/lib/python3.5/site-packages/django/urls/resolvers.py", line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/ajit/.local/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/ajit/.local/lib/python3.5/site-packages/django/urls/resolvers.py", line 306, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/ajit/Documents/Choice_feedback/Choice_feedback_main/Choice_feedback_main/urls.py", line 8, in <module>
url(r'^user/', include('registration_app.urls')),
File "/home/ajit/.local/lib/python3.5/site-packages/django/conf/urls/__init__.py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/ajit/Documents/Choice_feedback/Choice_feedback_main/registration_app/urls.py", line 10, in <module>
from registration_app.views import (
File "/home/ajit/Documents/Choice_feedback/Choice_feedback_main/registration_app/views.py", line 11, in <module>
from registration_app.forms import (
File "/home/ajit/Documents/Choice_feedback/Choice_feedback_main/registration_app/forms.py", line 45, in <module>
class AddtionalInformationForm(forms.Form):
File "/home/ajit/Documents/Choice_feedback/Choice_feedback_main/registration_app/forms.py", line 59, in AddtionalInformationForm
for grade in q:
File "/home/ajit/.local/lib/python3.5/site-packages/django/db/models/query.py", line 256, in __iter__
self._fetch_all()
File "/home/ajit/.local/lib/python3.5/site-packages/django/db/models/query.py", line 1087, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/ajit/.local/lib/python3.5/site-packages/django/db/models/query.py", line 54, in __iter__
results = compiler.execute_sql()
File "/home/ajit/.local/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 835, in execute_sql
cursor.execute(sql, params)
File "/home/ajit/.local/lib/python3.5/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/ajit/.local/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/ajit/.local/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/ajit/.local/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/ajit/.local/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/ajit/.local/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: student_app_grade
xlB
import roman
from collections import OrderedDict
from django.contrib.auth.forms import (
UserCreationForm,
UserChangeForm,
PasswordChangeForm
)
from django import forms
from django.contrib.auth.models import User
from student_app.models import Grade
class RegistrationForm(UserCreationForm):
email = forms.EmailField(required=True)
username = forms.CharField(max_length=24, widget=forms.TextInput(attrs={'name':"username"}))
class Meta:
model = User
fields = (
'username',
'email',
'password1',
'password2'
)
def save(self,commit = True):
user = super(RegistrationForm,self).save(commit = False)
# user.first_name = self.cleaned_data['first_name']
# user.last_name = self.cleaned_data['last_name']
user.email = self.cleaned_data['email']
if commit:
user.save()
return user
class EditProfileForm(UserChangeForm):
class Meta:
model = User
fields = (
'email',
'password'
)
class AddtionalInformationForm(forms.Form):
hash_class_ordered = []
hash_div_ordered = []
hash_class = []
hash_div = []
grade_ol = OrderedDict()
grade_ = []
grade_n = []
yq = []
div_ = []
div_n = []
grade_t = ()
q = Grade.objects.all()
for grade in q:
x = grade.grade
temp = x.split("-")
hash_class.append(temp[0])
hash_div.append(temp[1])
for c in hash_class:
if c not in grade_n:
grade_n.append(c)
for d in hash_div:
temp = (d, d)
if temp not in div_:
div_.append(temp)
div_.sort()
for h_c in grade_n:
h_c_n = roman.fromRoman(h_c)
temp = (h_c, h_c_n)
hash_class_ordered.append(temp)
hash_class_ordered.sort()
for c in hash_class_ordered:
c = (c[0], c[0])
yq.append(c)
grade = tuple(yq)
div = tuple(div_)
first_name = forms.CharField(max_length=20)
last_name = forms.CharField(max_length=20)
student_class_grade = forms.ChoiceField(choices=grade)
student_class_div = forms.ChoiceField(choices=div)
roll_no = forms.CharField(max_length=10)
推荐答案
尝试
- 重建迁移:python manage.py makemigrations student_app
- 迁移:python manage.py迁移
希望有帮助.
这篇关于OperationalError:删除数据库和迁移后没有这样的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!