如何在django中设置表的char列的编码? [英] How to set the encoding for the tables' char columns in django?
问题描述
manage.py syncdb
所有相应的列都使用cp1252字符集创建(在哪里找到 - 我没有想法),我必须手动更新每一列...
有没有办法告诉Django创建所有这些列与UTF-8编码首先?
BTW,我使用MySQL。
Django没有指定在 CREATE TABLE
语句中的字符集和排序规则。一切都由数据库字符集决定。执行 ALTER DATABASE ... CHARACTER SET utf8 COLLATE utf8_general_ci
在运行 syncdb
应该有帮助。
对于连接,Django自动发出 SET NAMES utf8
,所以您不需要担心默认连接字符集设置。
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
all respective columns are created with cp1252 character set (where did it get that -- I have no idea) and I have to manually update every column...
Is there a way to tell Django to create all those columns with UTF-8 encoding in the first place?
BTW, I use MySQL.
Django does not specify charset and collation in CREATE TABLE
statements. Everything is determined by database charset. Doing ALTER DATABASE ... CHARACTER SET utf8 COLLATE utf8_general_ci
before running syncdb
should help.
For connection, Django issues SET NAMES utf8
automatically, so you don't need to worry about default connection charset settings.
这篇关于如何在django中设置表的char列的编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!