kgill
kgill

Reputation: 5

Getting Characetr encoding error in django Incorrect string value: '\\xF0\\x9F\\x

I getting this error

django.db.utils.OperationalError: (1366, "Incorrect string value: '\xF0\x9F\x99\x8F \xF0...' for column 'html_code' at row 1")

I created database using this command

CREATE DATABASE sample CHARACTER SET utf8;

I have these settings in mysql

vim /etc/mysql/conf.d/mysql.cnf
[mysql]
default-character-set=utf8mb4

vim /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci

I even used this command as well

ALTER TABLE sample_randy CONVERT TO CHARACTER SET utf8

The problem is it worked first time i use those command and after sometime it again stop working with same error.

I am not sure which thing is resetting the options

If i delete the database, create again and run script again then it work again. if i rerun again then it get same error

Upvotes: 0

Views: 626

Answers (1)

Rick James
Rick James

Reputation: 142433

To get the character for 'PERSON WITH FOLDED HANDS', you needed utf8mb4 (not just utf8) everywhere. Do

ALTER TABLE sample_randy CONVERT TO CHARACTER SET utf8mb4

Upvotes: 3

Related Questions