为什么Django错误消息有空的类扩展名?

2024-06-20 15:16:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习如何使用Django,下面是this tutorial。 但是,每次尝试使用管理站点编辑数据库时,我都会遇到OperationalError异常

回溯:

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\backends\utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py" in execute
  296.         return Database.Cursor.execute(self, query, params)

The above exception (no such table: main.auth_user__old) was the direct cause of the following exception:

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\core\handlers\exception.py" in inner
  34.             response = get_response(request)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\core\handlers\base.py" in _get_response
  126.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\core\handlers\base.py" in _get_response
  124.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\contrib\admin\options.py" in wrapper
  604.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\contrib\admin\sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\contrib\admin\options.py" in change_view
  1639.         return self.changeform_view(request, object_id, form_url, extra_context)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\utils\decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\contrib\admin\options.py" in changeform_view
  1525.             return self._changeform_view(request, object_id, form_url, extra_context)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\contrib\admin\options.py" in _changeform_view
  1571.                     self.log_change(request, new_object, change_message)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\contrib\admin\options.py" in log_change
  826.             change_message=message,

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\contrib\admin\models.py" in log_action
  35.             change_message=change_message,

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\models\manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\models\query.py" in create
  413.         obj.save(force_insert=True, using=self.db)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\models\base.py" in save
  718.                        force_update=force_update, update_fields=update_fields)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\models\base.py" in save_base
  748.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\models\base.py" in _save_table
  831.             result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\models\base.py" in _do_insert
  869.                                using=using, raw=raw)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\models\manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\models\query.py" in _insert
  1136.         return query.get_compiler(using=using).execute_sql(return_id)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
  1289.                 cursor.execute(sql, params)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\backends\utils.py" in execute
  100.             return super().execute(sql, params)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\backends\utils.py" in execute
  68.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\backends\utils.py" in _execute_with_wrappers
  77.         return executor(sql, params, many, context)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\backends\utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\utils.py" in __exit__
  89.                 raise dj_exc_value.with_traceback(traceback) from exc_value

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\backends\utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

File "C:\Users\Zhang\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py" in execute
  296.         return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /admin/auth/user/2/change/
Exception Value: no such table: main.auth_user__old

我无法理解错误消息,因此我深入研究代码以了解它的含义。 在路径C:\Users\Zhang\AppData\Local\Continuum\anaconda3\Lib\site-packages\django\db中的文件utils.py中,我发现异常被实现为空类。 具体来说

class Error(Exception):
    pass


class InterfaceError(Error):
    pass


class DatabaseError(Error):
    pass


class DataError(DatabaseError):
    pass


class OperationalError(DatabaseError):
    pass


class IntegrityError(DatabaseError):
    pass


class InternalError(DatabaseError):
    pass


class ProgrammingError(DatabaseError):
    pass


class NotSupportedError(DatabaseError):
    pass

我想问的主要问题是:这样做有什么意义?为什么Django会留下一堆扩展Exception的空类? 而且,为什么Django有自己的sqlite3文件夹?据我所知,sqlite3已经包含在标准的Python3安装中,所以拥有自己的sqlite3库不是没有必要吗


Tags: djangoinpyexecutedblibpackageslocal