JIKE
    • 注册
    • 登录
    • 搜索
    • 版块
    • 最新
    • 标签
    • 热门
    • 用户

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

    技术分享
    django python
    1
    1
    508
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • malaohu
      我是小马甲~ 🤫 最后由 编辑

      最近再虚拟机上跑一个老项目 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 条回复 最后回复 回复 引用 0
      • 1 / 1
      • First post
        Last post