Categories
Python Answers

How to fix MySQL “incorrect string value” error when save unicode string in Python Django?

Spread the love

Sometimes, we want to fix MySQL "incorrect string value" error when save unicode string in Python Django.

In this article, we’ll look at how to fix MySQL "incorrect string value" error when save unicode string in Python Django.

How to fix MySQL "incorrect string value" error when save unicode string in Python Django?

To fix MySQL "incorrect string value" error when save unicode string in Python Django, we can change some options in the Django app settings.

To fix this, we write

DATABASES = {
    'default': {
        'ENGINE':'django.db.backends.mysql',
        ...
        'OPTIONS': {'charset': 'utf8mb4'},
    }
}

in settings.py.

We can use utf8mb4 characters with MySQL 5.5 or later.

Conclusion

To fix MySQL "incorrect string value" error when save unicode string in Python Django, we can change some options in the Django app settings.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *