Django Sqlite3编程错误

时间:2018-08-18 09:36:25

标签: python mysql django

我对Django非常陌生。我使用Python v3.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

Setting.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',
    }
}

请告诉我我做错了什么

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,并以此方式进行操作:

  1. 安装更新版本的sqlite3,即3.2.0
  2. 删除db.sqlite3(此后我没有创建新的文件)
  3. run command : python manage.py migrate
  4. python manage.py runserver
  5. python manage.py createsuperuser
  6. 登录,然后添加新用户或在模型表中添加一些内容。

祝你好运