Incorrect string value: ‘\xF0\x9F\x8C\xB8’ for column'xxx' at row 1, mysql storage of unusual characters/emoticons error

created at 07-15-2021 views: 3

Solve Incorrect string value: ‘\xF0\x9F\x8C\xB8’ for column'xxx' at row 1 error caused by storing unusual characters/emoticons into MySQL. 

note: you can avoid this problem by simply remove the unusual characters/emoticons from your content.

if you really need those unusual characters/emoticons, then bellow is your reference:

solution

The following statements need to be executed for each table created:

ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

The name of the data table corresponding to table_name.

Use django to change the connection method

DATABASES = {
    'default': {
        'ENGINE':'django.db.backends.mysql', # database engine
        'NAME':'', # Database name, previously created
        'USER':'', # database user name
        'PASSWORD':'',
        'HOST':'127.0.0.1',
        'PORT':'3306',
        'CHARSET':'utf8mb4', # Special attention
    }
}
Please log in to leave a comment.