pythondjangodatabasepostgresqldjango-models

Encoding problem when migrating postgresql database tables to models.py django


When performing table migration

python manage.py inspectdb > example/models.py

all Cyrillic strings are transposed as a set of unknown characters: 'id_шёїюф ∙хую' Encoding of the database server as well as python script is UTF-8. Is there any way to solve this problem?

I tried

show server_encoding;

and got UTF8, tried

set PYTHONIOENCODING=UTF-8

Also, I added

'OPTIONS': {
            'client_encoding': 'UTF8',
        }

into settings.py. All aforementioned methods didn't help and problem is still existing. I use psycopg package.


Solution

  • Solved the problem this way: I left the database in English, and when migrating entities to Django, renamed the model fields to Cyrillic, specifying db_name in models.py. After that everything is displayed correctly in both the application and the database