SqlAlchemy (1366, “Incorrect string value: '\\xB4\\xEB\\xC7\\xD1\\xB9\\xCE…' for column 'VARIABLE_VALUE' at row 484”)

99封情书 提交于 2021-01-28 23:26:44

问题


(1366, "Incorrect string value: '\xB4\xEB\xC7\xD1\xB9\xCE...' for column 'VARIABLE_VALUE' at row 484")

This error occurs whenever I try to insert a row (for anytable) But I don't have any table which contains 'VARIABLE_VAULE' column.

SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('VARIABLE_VALUE')
    AND TABLE_SCHEMA='sw';  /* nothing comes up */

How do I locate the table which causes the warning?


回答1:


The error happens because you are trying to store an emoji using the wrong charset. Change the charset from utf8 to utf8mb4




回答2:


The encoding used for Unicode has traditionally been 'utf8'. However, for MySQL versions 5.5.3 on forward, a new MySQL-specific encoding 'utf8mb4' has been introduced, and as of MySQL 8.0 a warning is emitted by the server if plain utf8 is specified within any server-side directives, replaced with utf8mb3. The rationale for this new encoding is due to the fact that MySQL’s legacy utf-8 encoding only supports codepoints up to three bytes instead of four. Therefore, when communicating with a MySQL database that includes codepoints more than three bytes in size, this new charset is preferred, if supported by both the database as well as the client DBAPI, as in:

e = create_engine(
    "mysql+pymysql://scott:tiger@localhost/test?charset=utf8mb4")
All modern DBAPIs should support the utf8mb4 charset.

enter link description here



来源:https://stackoverflow.com/questions/50653500/sqlalchemy-1366-incorrect-string-value-xb4-xeb-xc7-xd1-xb9-xce-f

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!