Incorrect String error when adding emoji to a database through a form

后端 未结 3 1811
终归单人心
终归单人心 2021-01-20 02:09

I can successfully add emoji (i.e. utf8mb4 data) to tables using mysql using the terminal.

When my Python Flask website tries to send emoji to the same database tabl

3条回答
  •  感情败类
    2021-01-20 03:01

    Python Flask defaults to communicating with MySQL in MySQL's utf-8, i.e. it can't handle the full utf8mb4 range (which includes emojis). Flask will override the database charset settings, including the character-set-server setting in my.cf. Adding the following setting to the Flask app fixes the problem by forcing it to communicate with MySQL in utf8mb4:

    app.config['MYSQL_DATABASE_CHARSET'] = 'utf8mb4'

提交回复
热议问题