python + django + Mysql中的字符串值不正确

时间:2015-02-21 22:47:03

标签: python mysql django

错误详情:

Warning at /admin/cute/cute/
Incorrect string value: '\xF0\x9F\x98\x89\xE7\x93...' for column 'object_repr' at row 1
Request Method: POST
Request URL:    http://api.ourcute.com/admin/cute/cute/?recommend__exact=0
Django Version: 1.7.1
Exception Type: Warning
Exception Value:    
Incorrect string value: '\xF0\x9F\x98\x89\xE7\x93...' for column 'object_repr' at row 1
Exception Location: /usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py in _warning_check, line 117
Python Executable:  /usr/local/bin/uwsgi
Python Version: 2.7.3
Python Path:    
['/opt/cute_project/server/server/',
 '/opt/cute_project/server/uwsgi/',
 '/opt/cute_project/server/',
 '.',
 '/opt/cute_project/server',
 '/opt/cute_project/server/server/src/django-cache-machine',
 '/usr/local/lib/python2.7/dist-packages/oss-0.1.3-py2.7.egg',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages']
Server time:    星期日, 22 二月 2015 06:34:27 +0800

错误位于django管理页面,该页面由管理员模板生成。 所以我猜应该是mysql设置错误。

1 个答案:

答案 0 :(得分:0)

如果那是一个4字节"眨眼的面孔"在utf8中,你需要在MySQL中从utf8更改为utf8mb4。