JIKE
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users

    django.db.utils.DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread

    技术分享
    django python
    1
    1
    397
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • malaohu
      我是小马甲~ 🤫 last edited by

      最近再虚拟机上跑一个老项目 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)即可

      唐宋元明清,连排小工兵!

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post