Django uses utf8mb4 character set

Recently, in the process of using the operation and maintenance platform, when I found that the submitted SQL statement contains an expression, part of the data will be lost when it is stored in the database. For example, the original sentence is "update a set c='aaa emoji expression \n\n ~emoji expression" \n\n'", it becomes "update a set c='aaa emoji" after being stored in the library. Later, this problem was solved using the utf8mb4 character set. Django uses the utf8mb4 character set and performs the following configuration:

  1. The database configuration is as follows:

[client] 
default-character-set = utf8mb4  
[mysql]  
default-character-set = utf8mb4 
[mysqld]  
character-set-client-handshake = FALSE  
character-set-server = utf8mb4  
collation-server = utf8mb4_unicode_ci

2.django configuration

DATABASES = { 
'default': {  
        ...
        'OPTIONS': {'charset':'utf8mb4'},  
    },  
}




Guess you like

Origin blog.51cto.com/jack88/2675781