我正在使用Python V3.6和Django V2.1创建一个示例应用程序,以前我遇到过与MySQL客户端有关的问题,因此我已通过使用“ pip install "mysqlclient==1.3.12”修复了该问题,可帮助成功安装mysqlclient,但稍后当我尝试运行我的应用程序时,出现以下错误。

Performing system checks...

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: (1045, "Access denied for user 'ODBC'@'localhost' (using password: NO)")
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 1776 and this is thread id 10192


Setting.py

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


如果我尝试使用默认数据库(sqlite3),则可以正常工作,但是当我尝试将其更改为Mysql时,出现此错误。

最佳答案

确保您提供了有效的凭据并安装了最新的mysqlclient。要安装mysqlclient,请使用命令pip install -I mysqlclient

关于python - 无法启动python manager.py runserver,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51897079/

10-12 16:54