django-1366, "Incorrect string value: '\\xE6\\x88\\x9A\\xE4\\xBC\\x9F...'

时间:2023-01-10 17:51:58

今天把之前的一些代码转移到另外一台电脑的时候,

python manage.py syncdb 

的时候报了

(1366, "Incorrect string value: '\\xE6\\x88\\x9A\\xE4\\xBC\\x9F...'

的错误,查了一下,应该是数据库编码设置的问题,看了一下本机数据库的默认编码,果然如此

mysql> show variables like "%char%";
+--------------------------+--------------------------------------------------------+
| Variable_name            | Value                                                  |
+--------------------------+--------------------------------------------------------+
| character_set_client     | utf8                                                   |
| character_set_connection | utf8                                                   |
| character_set_database   | latin1                                                 |
| character_set_filesystem | binary                                                 |
| character_set_results    | utf8                                                   |
| character_set_server     | latin1                                                 |
| character_set_system     | utf8                                                   |
| character_sets_dir       | /usr/local/mysql-5.7.11-osx10.9-x86_64/share/charsets/ |
+--------------------------+--------------------------------------------------------+
8 rows in set (0.01 sec)

mysql> set character_set_database='utf8';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> set character_set_server='utf8';
Query OK, 0 rows affected (0.00 sec)

把latin1的那两个编码改为utf8就没问题了