P
P
pvgdrk2014-10-21 01:09:04
MySQL
pvgdrk, 2014-10-21 01:09:04

Why do we get Incorrect string value when trying to save a value in django admin?

Yes, this has been discussed many times, and there seem to be solutions that helped (I was also helped before, now for some reason they don’t help - stackoverflow.com/questions/2108824/mysql-incorrec...
But this question is a bit about something else. The reason for this error the fact is that there are more bytes somewhere in mysql than it should be and therefore it is not saved.But if it's in mysql why then through the pycharm database manager I have the same string perfectly saved, but through the django administrative interface I get an error? -something wrong in django?
I don't know what information from the settings can be shown, these last three lines in my opinion are generally useless - what is, what is not:

DATABASES = {
    'default': {
        ...
        'OPTIONS': {
            'init_command': 'SET storage_engine=INNODB, '
                            'character_set_connection = utf8, '
                            'collation_connection = utf8_unicode_ci, '
                            'collation_database = utf8_unicode_ci, collation_server = utf8_unicode_ci'
        },
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alternativshik, 2014-10-21
@pvgdrk

you do not need utf8, but utf8mb4, if you really have a problem there in what you wrote (for example, to save emoji). Treated by converting the base to utf8mb4 (mysql >= v5.5), + in settings

import codecs

#Хак для работы с "utf8mb4"
codecs.register(lambda name: codecs.lookup('utf8') if name == 'utf8mb4' else None)

and in the database settings:
'OPTIONS': {
            'charset': 'utf8mb4',
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question