django sqlite3编程错误

tyg4sfes  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(333)

我对django很陌生。我用pythonv3.6和django v2.1创建了一个示例项目。最初,我使用的是默认的sqlite3数据库,但现在我们计划将其改为mysql。为此,我安装了所有必要的插件。另一方面,除了admin之外,我没有用sqlite3创建任何表。
如果它是在默认数据库中,当我将其更改为mysql时,它可以正常工作。我得到了一个星期内无法解决的错误:-(

System check identified no issues (0 silenced).
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0000000003A93C80>
Traceback (most recent call last):
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\django\db\backends\base\base.py", line 2
16, in ensure_connection

    self.connect()
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\django\db\backends\base\base.py", line 1
94, in connect
    self.connection = self.get_new_connection(conn_params)
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\django\db\backends\mysql\base.py", line
227, in get_new_connection
    return Database.connect(**conn_params)
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MySQLdb\__init__.py", line 86, in Connec
t
    return Connection(*args,**kwargs)
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MySQLdb\connections.py", line 204, in __
init__
    super(Connection, self).__init__(*args,**kwargs2)
_mysql_exceptions.OperationalError: (2059, "Authentication plugin 'caching_sha2_password' cannot be loaded: The speci
fied module could not be found.\r\n")      
self.connect()
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\django\db\utils.py", line 89, in __exit_
_
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\django\db\backends\base\base.py", line 2
16, in ensure_connection
    self.connect()
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\django\db\backends\base\base.py", line 1
94, in connect

    self.connection = self.get_new_connection(conn_params)
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\django\db\backends\mysql\base.py", line
227, in get_new_connection
    return Database.connect(**conn_params)
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MySQLdb\__init__.py", line 86, in Connec
t
    return Connection(*args,**kwargs)
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MySQLdb\connections.py", line 204, in __
init__
self.connect()
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\django\db\utils.py", line 89, in __exit_
_
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\django\db\backends\base\base.py", line 2
16, in ensure_connection
    self.connect()
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\django\db\backends\base\base.py", line 1
94, in connect

    self.connection = self.get_new_connection(conn_params)
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\django\db\backends\mysql\base.py", line
227, in get_new_connection
    return Database.connect(**conn_params)
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MySQLdb\__init__.py", line 86, in Connec
t
    return Connection(*args,**kwargs)
  File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MySQLdb\connections.py", line 204, in __
init__
django.db.utils.OperationalError: (2059, "Authentication plugin 'caching_sha2_password' cannot be loaded: The specifi
ed module could not be found.\r\n")

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True

Error in atexit._run_exitfuncs:
    Traceback (most recent call last):
      File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\IPython\core\history.py", line 780, in w
    riteout_cache
        self._writeout_input_cache(conn)
      File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\IPython\core\history.py", line 764, in _
    writeout_input_cache
        (self.session_number,)+line)

    sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was crea
    ted in thread id 2548 and this is thread id 11036

设置.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'shield_dev',
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}

请让我知道我做错了什么

2w2cym1i

2w2cym1i1#

我也遇到了同样的问题,继续这样做:
安装更新版本的sqlite3,即3.2.0
删除db.sqlite3(之后我没有创建新的) run command : python manage.py migrate python manage.py runserver python manage.py createsuperuser 登录,然后添加新用户或在模型表中添加一些内容。
祝你好运

相关问题