Emogi storage in MySQL(encoding problem)

项月亮
1 min readApr 21, 2020

In Django project, when you create database and tables through model.py, the default encoding is utf-8, which you can see clearly in Navicat. But this encoding restrict the size of single unicode character to 3 Bytes. When you need to store larger size character like emogi(4 Bytes), MySQL will reporte an error.

django.db.utils.OperationalError: (1366, "Incorrect string value:...

So to avoid this problem, change the encoding to utf8mb4 , which has to new features:

  1. Requires a maximum of four bytes per multibyte character
  2. Supports BMP and supplementary characters.

The change command is following

ALTER TABLE TABLENAME CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response