Django + MySQL - Unknown encoding: utf8mb4

前端 未结 3 1248
[愿得一人]
[愿得一人] 2021-02-08 23:08

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\'}


        
相关标签:
3条回答
  • 2021-02-08 23:41

    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)
    
    0 讨论(0)
  • 2021-02-08 23:44

    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 !

    0 讨论(0)
  • 2021-02-08 23:49

    Fast and easy way.

    connection = mysql.connector.connect(user='username',
                                       password='mypass',
                                        host='localhost',
                                         database='mydb',
                                           use_pure=True,
                                          charset='utf8'
                                          )
    
    0 讨论(0)
提交回复
热议问题