django.db.utils.DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread
-
最近再虚拟机上跑一个老项目 Python Django代码,突然报错了~
File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line elif self.argv[1:] in (['--help'], ['-h']): File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute elif len(options.args) < 1: File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 360, in run_from_argv ) File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 235, in close_all File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 263, in close # A successful commit means that the database connection works. File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 523, in validate_thread_sharing if self.close_at is not None and time.time() >= self.close_at: django.db.utils.DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 140018405640000 and this is thread id 140017984312336. Exception KeyError: KeyError(140017984312336,) in <module 'threading' from '/usr/local/lib/python2.7/threading.pyc'> ignored
经过一番搜索,发现问题所在了!
第一,我将Python 2 版本升级到 2.7.18
第二,Django版本 1.9.6运行Django项目出现错误
卸载原Django库,新安装 最新版本的Django(1.11.29)即可