Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django + MySQL - Unknown encoding: utf8mb4

Tags:

mysql

django

MySQL 5.5.35 Django 1.6.1

In order to support emoticons in the DB, I have configured in my django settings:

'OPTIONS': {'charset': 'utf8mb4'}

On MySQL connection, I get this error: LookupError: unknown encoding: utf8mb4

How should I configure Django/MySQL in order to support utf8mb4?

like image 507
Amit Talmor Avatar asked Feb 02 '14 22:02

Amit Talmor


Video Answer


2 Answers

https://code.djangoproject.com/ticket/18392#comment:10

As a workaround, you can make python understand 'utf8mb4' as an alias for 'utf8':

import codecs
codecs.register(lambda name: codecs.lookup('utf8') if name == 'utf8mb4' else None)
like image 167
Tim Tisdall Avatar answered Sep 18 '22 15:09

Tim Tisdall


If you really need utf8mb4, follow the steps in https://mathiasbynens.be/notes/mysql-utf8mb4, and make sure your python package "MySQL-python" version is >= 1.2.5 !

like image 37
nanchen Avatar answered Sep 21 '22 15:09

nanchen