Reputation: 1896
I'm trying to insert an emoji into my title
column in my django + MySQL app.
I edited the database directly with PhpMyAdmin. I changed the charset of the column to utf8mb4_unicode_ci
and manually inserted an emoji in the table.
And this is the table row with an emoji:
But when I open this object in the django admin, the emoji is missing:
And if I try to enter the emoji and save, I get this exception:
MySQLdb._exceptions.OperationalError: (1366, "Incorrect string value: '\\\\xF0\\\\x9F\\\\x92\\\\xA9' for column 'title' at row 1")
What am I missing?
Upvotes: 0
Views: 1771
Reputation: 1896
What's missing is the charset
option for the mysql database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
...
'OPTIONS': {
...
'charset': 'utf8mb4',
},
}
}
Upvotes: 7