Typeorm not using default charset from database
See original GitHub issueIssue type:
[ ] question [ x ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ x ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ x ] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
From MySQL connection options:
/**
* The charset for the connection. This is called "collation" in the SQL-level of MySQL (like utf8_general_ci).
* If a SQL-level charset is specified (like utf8mb4) then the default collation for that charset is used.
* Default: 'UTF8_GENERAL_CI'
*/
readonly charset?: string;
Using the SQL-level charset seems not to work properly. My MySQL database is configured as:
Default collation: utf8mb4_unicode_ci
Default charset: utf8mb4
When inserting a string, that contains an emoji, the query fails with:
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
, 'Incorrect string value: \'\\xF0\\x9F\\x98\\x9C \' for column \'message\' at row 1',
That indicates, that the default charset of the database is not used, and the default UTF8_GENERAL_CI
used instead (which does not support emoji).
And in deed, if I set charset: 'utf8mb4'
explicitly in the typeorm config, inserting works properly.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
@robertoandres24 Can you clarify what exactly worked? I’m having a similar issue and my column types are set to ‘uft8mb4’, but I’m still getting the error message
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value: '\xE2\x80\x90tim...' for column 'content' at row 1