美文网首页
SyntaxError: (1366, "Incorrect s

SyntaxError: (1366, "Incorrect s

作者: 梨花菜 | 来源:发表于2020-01-07 14:21 被阅读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数据库配置的字符集

image.png

相关文章

网友评论

      本文标题:SyntaxError: (1366, "Incorrect s

      本文链接:https://www.haomeiwen.com/subject/tbvractx.html