I got the error below in django when saving a field with emoji character in the admin panel.
OperationalError at /admin/core/message/add/ (1366, "Incorrect string value: '\xF0\x9F\x98\x9E \xF0...' for column 'name' at row 1")
I'm sure the database is ready for utf8mb4, because I can write/read these emoji character in phpmyadmin.
More, the saved emoji character displayed correctly in phpmyadmin but displays ??? in django output.
And in my another django project, the emoji plays well, till I just cannot find the difference between the two environment.
So what can be the problem when I save the same thing using python?
The problem is under django framework, so I want a solution that make django work.
Setting DATABASE section in the settings.py with OPTIONS - charset solves this issue:
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'myproject',
'HOST': 'mysql',
'USER': 'django',
'PASSWORD': '******',
'OPTIONS': {
# !!!!!! THIS MATTERS !!!!!!
'charset': 'utf8mb4',
}
},
}
See documentation: https://docs.djangoproject.com/en/1.10/ref/settings/#charset
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With