Answer the question
In order to leave comments, you need to log in
How to add Russian characters to MySql in Django on encoding error?
In models, the field is like charfield.
English characters are entered without problems.
And the Russian is given an error.
Exception Type: OperationalError
Exception Value:
(1366, "Incorrect string value: '\\xD0\\x94\\xD0\\xB8\\xD0\\xBC...' for column 'title' at row 1")
class TbRecNews(models.Model):
url = models.CharField(max_length=150)
user = models.IntegerField()
title = models.CharField(max_length=100)
mysqld --verbose --help grep character-set
mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 13 - Permission denied)
2019-04-20T07:44:18.640883Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2019-04-20T07:44:18.640997Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
--character-set-client-handshake
(Defaults to on; use --skip-character-set-client-handshake to disable.)
--character-set-filesystem=name
-C, --character-set-server=name
--character-sets-dir=name
character-set-client-handshake TRUE
character-set-filesystem binary
character-set-server latin1
character-sets-dir /usr/share/mysql/charsets/
mysql> SHOW VARIABLES LIKE 'character_set%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.04 sec)
mysql> SHOW VARIABLES LIKE 'collation%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'character_set%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
mysql> SHOW VARIABLES LIKE 'collation%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
Answer the question
In order to leave comments, you need to log in
Check the database connection encoding in the DATABASES settings, check the created tables and make sure that the encoding is the same everywhere and ideally utf-8
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question