操作错误,Django中没有此类表错误

时间:2019-05-28 05:40:00

标签: python django django-models django-admin

我的项目中有三个数据库表。当我应用迁移时,它们将成功应用,并且在管理站点上也可见。但是,当我在管理站点上单击三个数据库表之一时,出现操作错误,指出该表不存在。这两个表的其余部分正常工作。 我尝试删除迁移文件夹,然后再次应用迁移。但是重复同样的错误。 错误如下

db.getCollection('messagelogs').find({'date': {'$gte': '20-05-2019', '$lt': '31-05-2019'}})  

admin.py

Internal Server Error: /admin/users/subscription/
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\backen
ds\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\backen
ds\sqlite3\base.py", line 303, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: users_subscription

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\core\hand
lers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\core\hand
lers\base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\core\hand
lers\base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\contrib\a
dmin\options.py", line 574, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\utils\dec
orators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\views\dec
orators\cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\contrib\a
dmin\sites.py", line 223, in inner
    return view(request, *args, **kwargs)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\utils\dec
orators.py", line 62, in _wrapper
    return bound_func(*args, **kwargs)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\utils\dec
orators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\utils\dec
orators.py", line 58, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\contrib\a
dmin\options.py", line 1570, in changelist_view
    cl = self.get_changelist_instance(request)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\contrib\a
dmin\options.py", line 705, in get_changelist_instance
    self,
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\contrib\a
dmin\views\main.py", line 77, in __init__
    self.get_results(request)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\contrib\a
dmin\views\main.py", line 175, in get_results
    result_count = paginator.count
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\utils\fun
ctional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\core\pagi
nator.py", line 85, in count
    return self.object_list.count()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\models
\query.py", line 387, in count
    return self.query.get_count(using=self.db)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\models
\sql\query.py", line 491, in get_count
    number = obj.get_aggregation(using, ['__count'])['__count']
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\models
\sql\query.py", line 476, in get_aggregation
    result = compiler.execute_sql(SINGLE)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\models
\sql\compiler.py", line 1066, in execute_sql
    cursor.execute(sql, params)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\backen
ds\utils.py", line 100, in execute
    return super().execute(sql, params)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\backen
ds\utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\backen
ds\utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\backen
ds\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\utils.
py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\backen
ds\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.0.3-py3.7.egg\django\db\backen
ds\sqlite3\base.py", line 303, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: users_subscription

当我单击管理站点上的“订阅”表时,发生错误。 “用户”是我的应用名称。

当我应用迁移时,将显示以下内容。从这一点上,我认为可以确保已创建表Subscription。

from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin

from .forms import CustomUserCreationForm, CustomUserChangeForm
from .models import CustomUser, Profile, Subscription

class CustomUserAdmin(UserAdmin):
    add_form = CustomUserCreationForm
    form = CustomUserChangeForm
    model = CustomUser
    list_display = ['email', 'username','password1','password2']

admin.site.register(CustomUser, CustomUserAdmin)
admin.site.register(Profile)
admin.site.register(Subscription)

0 个答案:

没有答案