【发布时间】:2017-04-26 04:29:51
【问题描述】:
我在 settings.py 中配置了我的 Django 数据库设置:
'OPTIONS': {'charset': 'utf8mb4'},
所有列和表都设置为 utf8mb4。
我想要这种编码,这样我就可以存储以下表情符号:????????????????????
当我在 Mac 或 Linux 上启动我的脚本时,它运行良好,但在 Windows 上,我得到:
<module> C:\Users\Josh\Documents\mysite\myproj\scripts\crawler.py 154
__getitem__ C:\Python27\Lib\site-packages\django\db\models\query.py 295
__iter__ C:\Python27\Lib\site-packages\django\db\models\query.py 256
_fetch_all C:\Python27\Lib\site-packages\django\db\models\query.py 1087
__iter__ C:\Python27\Lib\site-packages\django\db\models\query.py 54
execute_sql C:\Python27\Lib\site-packages\django\db\models\sql\compiler.py 833
cursor C:\Python27\Lib\site-packages\django\db\backends\base\base.py 231
_cursor C:\Python27\Lib\site-packages\django\db\backends\base\base.py 204
ensure_connection C:\Python27\Lib\site-packages\django\db\backends\base\base.py 199
__exit__ C:\Python27\Lib\site-packages\django\db\utils.py 94
ensure_connection C:\Python27\Lib\site-packages\django\db\backends\base\base.py 199
connect C:\Python27\Lib\site-packages\django\db\backends\base\base.py 171
get_new_connection C:\Python27\Lib\site-packages\django\db\backends\mysql\base.py 263
Connect c:\users\josh\appdata\local\temp\easy_install-iz3bc1\MySQL_python-1.2.5-py2.7-win32.egg.tmp\MySQLdb\__init__.py 81
__init__ c:\users\josh\appdata\local\temp\easy_install-iz3bc1\MySQL_python-1.2.5-py2.7-win32.egg.tmp\MySQLdb\connections.py 221
set_character_set c:\users\josh\appdata\local\temp\easy_install-iz3bc1\MySQL_python-1.2.5-py2.7-win32.egg.tmp\MySQLdb\connections.py 312
"OperationalError: (2019, ""Can't initialize character set utf8mb4 (path: C:\\mysql\\\\share\\charsets\\)"")"
它引发异常的代码行是:
Object.objects.filter(last_scraped__isnull=True)[0]
版本:
Python 2.7
数据库:MariaDB 5.5
Windows 7 64 位
【问题讨论】:
-
只有在运行
manage.py时才会发生这种情况吗? -
尝试使用标准的 'utf8' - 它几乎涵盖了所有符号。
-
@AndreyShipilov 不,这是由 Apache 在 CentOS 服务器上运行的。
-
@EugeneLisitsky 真的吗?你知道它覆盖和不覆盖多少个 iPhone 表情符号吗?
-
@user,是的,因为 SO 以 utf-8 编码输出它们。这是一个标题:
Content-Type: text/html; charset=utf-8
标签: python mysql django windows mariadb