问题:
前端POST请求中包含中文内容时,出现如下错误:
Exception Type: OperationalError at /api/notification/eventadjustment/
Exception Value: (1366, “Incorrect string value: ‘\xE7\x9B\xB8\xE5\x90\x8C…’ for column ‘comment’ at row 1”)
或者django 修改用户时的报错
OperationalError at /api/admin/auth/user/2/
(1366, “Incorrect string value: ‘\xE6\xB2\xA1\xE6\x9C\x89…’ for column ‘change_message’ at row 1”)
或者
OperationalError at /api/admin/auth/group/add/
(1267, “Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation ‘=’”)
原因:
后台DB表及字段编码问题。
解决办法:
首先,设置表的编码utf8。
ALTER TABLE orange
CHARACTER SET = utf8 ;
其次,设置字段的编码utf8。
ALTER TABLE orange
CHANGE COLUMN `comment` `comment` VARCHAR(255) SET 'utf8' NOT NULL DEFAULT '' ;