How to embed emoji in MYSQL 5.5 and higher using Django ORM

I am trying to insert emoji into a specific folder in my mysql table. I ran the alter command and changed the sorting to "utf8mb4_general_ci"

ALTER TABLE XYZ MODIFY description VARCHAR(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; 

Details of the table upon request:

 +-------------+--------------+---------------+--------------------+ | Column | Type | Character Set | Collation | +-------------+--------------+---------------+--------------------+ | description | varchar(250) | utf8mb4 | utf8mb4_general_ci | +-------------+--------------+---------------+--------------------+ 

After that, I ran a query to update the description column with emoji, every time I ran the query below, emoji is replaced with ??.

  update XYZ set description='a test with : 😄😄' where id = 1; 

But when I print the result of a select query for the same identifier, does it display ''? 'instead of emoji. The result is:

  "a test with : ??" 

The necessary changes have occurred in the model file. Accept my apologies for what you did not understand, would appreciate the leading role in this matter.

+5
source share
1 answer
 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', ... 'OPTIONS': { 'charset': 'utf8mb4', 'use_unicode': True, }, }, } 

my.cnf :

 [mysqld] character-set-server=utf8mb4 default-collation=utf8mb4_unicode_ci [client] default-character-set=utf8mb4 
+1
source

Source: https://habr.com/ru/post/1268767/


All Articles