V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
superbai
V2EX  ›  Python

django 如何在创建表的时候设置 charset 为 utf8

  •  
  •   superbai · 2019-10-17 17:39:55 +08:00 · 3418 次点击
    这是一个创建于 1624 天前的主题,其中的信息可能已经有所发展或是发生改变。
    django2.2.6,通过 django 自带的 python manage.py migrate 命令建表之后,发现表的 charset 是 latin1,如何设置让 django 创建表的时候默认 charset 是 utf8 呢?
    6 条回复    2019-10-19 19:08:52 +08:00
    janxin
        1
    janxin  
       2019-10-17 17:46:02 +08:00
    DATABASES 里面配置了吗
    superbai
        2
    superbai  
    OP
       2019-10-17 17:47:34 +08:00
    @janxin #1 是指 option 里面吗?
    elioti
        3
    elioti  
       2019-10-17 22:44:15 +08:00
    不是先去数据库里创建的时候 用 create database xxx charset=utf8;指明吗
    superbai
        4
    superbai  
    OP
       2019-10-17 22:47:56 +08:00
    @elioti #3 是的,最后用这种方法解决了。但是想知道 django 的 model 里有没有关于字符编码的设置项
    a852695
        5
    a852695  
       2019-10-18 09:23:36 +08:00
    django 可以设置 但是如果你 create db 时候不是 utf8 它也修改不鸟
    superbai
        6
    superbai  
    OP
       2019-10-19 19:08:52 +08:00
    @a852695 #5 在哪里设置?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3337 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:41 · PVG 21:41 · LAX 06:41 · JFK 09:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.