SyntaxError: (1366, "Incorrect s
2020-01-07 本文已影响0人
梨花菜
1.检查表的字符集
mysql> show full columns from reportdetail;
+----------------+----------+-----------------+------+-----+---------+----------------+---------------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+----------------+----------+-----------------+------+-----+---------+----------------+---------------------------------+---------+
| id | int(11) | NULL | NO | PRI | NULL | auto_increment | select,insert,update,references | |
| summary_detail | longtext | utf8_unicode_ci | NO | | NULL | | select,insert,update,references | |
+----------------+----------+-----------------+------+-----+---------+----------------+---------------------------------+---------+
2 rows in set (0.05 sec)
可以看到summary_detail
字段的字符集是utf8_unicode_ci
,这是无法保存emoji表情包的
2.修改表字段的字符集为utf8mb4_unicode_ci
# 修改为utf8mb4_unicode_ci
mysql> ALTER TABLE reportdetail
CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Query OK, 1 row affected (0.11 sec)
Records: 1 Duplicates: 0 Warnings: 0
# 再次查看表字段的字符集已经改为 utf8mb4_unicode_ci
mysql> show full columns from reportdetail;
+----------------+----------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+----------------+----------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
| id | int(11) | NULL | NO | PRI | NULL | auto_increment | select,insert,update,references | |
| summary_detail | longtext | utf8mb4_unicode_ci | NO | | NULL | | select,insert,update,references | |
+----------------+----------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
2 rows in set (0.06 sec)
3.修改Django数据库配置的字符集
