回到顶部

阅读目录

pymysql charset.py return self._by_id[id] KeyError: 255

启动环境

  • mysql==8.0
  • python==3.6
  • pymysql==0.7.11

错误日志

(joyo) E:\git_stores\blog>python manage.py migrate
E:\py_envs\joyo\lib\site-packages\daphne\server.py:15: UserWarning: Something has already installed a non-asyncio Twisted reactor. Attempting to uninstall it; you can fix this warning by importing daphne.server early in your codebase or finding the package that imports Twisted and importing it later on.
  UserWarning,
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "E:\py_envs\joyo\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "E:\py_envs\joyo\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "E:\py_envs\joyo\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "E:\py_envs\joyo\lib\site-packages\django\core\management\base.py", line 361, in execute
    self.check()
  File "E:\py_envs\joyo\lib\site-packages\django\core\management\base.py", line 390, in check
    include_deployment_checks=include_deployment_checks,
  File "E:\py_envs\joyo\lib\site-packages\django\core\management\commands\migrate.py", line 64, in _run_checks
    issues = run_checks(tags=[Tags.database])
  File "E:\py_envs\joyo\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "E:\py_envs\joyo\lib\site-packages\django\core\checks\database.py", line 10, in check_database_backends
    issues.extend(conn.validation.check(**kwargs))
  File "E:\py_envs\joyo\lib\site-packages\django\db\backends\mysql\validation.py", line 9, in check
    issues.extend(self._check_sql_mode(**kwargs))
  File "E:\py_envs\joyo\lib\site-packages\django\db\backends\mysql\validation.py", line 13, in _check_sql_mode
    with self.connection.cursor() as cursor:
  File "E:\py_envs\joyo\lib\site-packages\django\db\backends\base\base.py", line 256, in cursor
    return self._cursor()
  File "E:\py_envs\joyo\lib\site-packages\django\db\backends\base\base.py", line 233, in _cursor
    self.ensure_connection()
  File "E:\py_envs\joyo\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
    self.connect()
  File "E:\py_envs\joyo\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
    self.connection = self.get_new_connection(conn_params)
  File "E:\py_envs\joyo\lib\site-packages\django\db\backends\mysql\base.py", line 227, in get_new_connection
    return Database.connect(**conn_params)
  File "E:\py_envs\joyo\lib\site-packages\pymysql\__init__.py", line 90, in Connect
    return Connection(*args, **kwargs)
  File "E:\py_envs\joyo\lib\site-packages\pymysql\connections.py", line 706, in __init__
    self.connect()
  File "E:\py_envs\joyo\lib\site-packages\pymysql\connections.py", line 931, in connect
    self._get_server_information()
  File "E:\py_envs\joyo\lib\site-packages\pymysql\connections.py", line 1269, in _get_server_information
    self.server_charset = charset_by_id(lang).name
  File "E:\py_envs\joyo\lib\site-packages\pymysql\charset.py", line 38, in by_id
    return self._by_id[id]
KeyError: 255
Sentry is attempting to send 1 pending error messages
Waiting up to 10 seconds
Press Ctrl-Break to quit

错误原因

PyMySQL==0.7.11 不兼容 mysql8

解决办法

只需要升级 pymysql 就可以了

目标版本 PyMySQL==1.0.2

PyMySQL · PyPI

pip install PyMySQL --upgrade

 


^_^
请喝咖啡 ×

本作品由 卓越笔记 采用 知识共享署名 - 非商业性使用 - 相同方式共享 4.0 国际许可协议 进行许可

前一篇: django 2.2 sqlite3 迁移到 mysql8 报错:return instance._state.fields_cache[cache_name] KeyError: 'article'
下一篇: docker 启动失败:Failed to start Docker Application Container Engine