How to set the encoding for the tables' char columns in django?

前端 未结 3 416
耶瑟儿~
耶瑟儿~ 2020-12-13 15:59

I have a project written in Django. All fields that are supposed to store some strings are supposed to be in UTF-8, however, when I run

manage.py syncdb
         


        
3条回答
  •  执念已碎
    2020-12-13 16:12

    Django’s database backends automatically handles Unicode strings into the appropriate encoding and talk to the database. You don’t need to tell Django what encoding your database uses. It handles it well, by using you database's encoding.

    I don't see any way you can tell django to create a column, using some specific encoding. As it appears to me, there is absolutely some previous MySQL configuration affecting you. And despite of doing it manually for all column, use these.

    CREATE DATABASE db_name
        [[DEFAULT] CHARACTER SET charset_name]
        [[DEFAULT] COLLATE collation_name]
    
    ALTER DATABASE db_name
        [[DEFAULT] CHARACTER SET charset_name]
        [[DEFAULT] COLLATE collation_name]
    

提交回复
热议问题