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
ciba1990
V2EX  ›  Python

django models.TextField() 不能存中文

  •  
  •   ciba1990 · 2015-07-26 19:15:43 +08:00 · 7561 次点击
    这是一个创建于 3198 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Incorrect string value: '\xE6\x94\xB9\xE7\xAB\xAF...' for column 'name_post' at row 1
    name_post = models.TextField()
    手动print出来又是中文,
    在后台admin里面手动改成中文保存还是报错,数据保存形式都改成utf-8了。
    +--------------------------+----------------------------+
    | Variable_name | Value |
    +--------------------------+----------------------------+
    | character_set_client | utf8 |
    | character_set_connection | utf8 |
    | character_set_database | utf8 |
    | character_set_filesystem | binary |
    | character_set_results | utf8 |
    | character_set_server | utf8 |
    | character_set_system | utf8 |
    | character_sets_dir | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+

    12 条回复    2015-07-27 18:57:04 +08:00
    ciba1990
        1
    ciba1990  
    OP
       2015-07-26 19:17:01 +08:00
    数据库是mariadb,是不是数据库设置有问题。
    ciba1990
        2
    ciba1990  
    OP
       2015-07-26 19:21:18 +08:00
    英文就一点问题没有,奇了怪了。
    lixia625
        3
    lixia625  
       2015-07-26 22:23:03 +08:00
    "\xE6\x94\xB9\xE7\xAB\xAF".decode('utf8')
    virusdefender
        4
    virusdefender  
       2015-07-26 23:21:24 +08:00
    你怎么创建的数据库?

    create database xxx default character set utf-8;

    一直没问题
    ciba1990
        5
    ciba1990  
    OP
       2015-07-26 23:35:25 +08:00 via iPhone
    @virusdefender 换成自带的sqlite3就没问题
    virusdefender
        6
    virusdefender  
       2015-07-26 23:37:07 +08:00 via Android
    @ciba1990 肯定是mysql编码问题 试试上面我说的
    qqblog
        7
    qqblog  
       2015-07-26 23:42:21 +08:00
    不能同意更多,mysql编码坑,退mysql保平安
    mugbya
        8
    mugbya  
       2015-07-27 09:37:09 +08:00
    来 postgresql
    shenxgan
        9
    shenxgan  
       2015-07-27 10:18:29 +08:00
    我用的没有问题,中文也可以。我是这样创建数据库的:

    create database xblog default charset utf8 collate utf8_general_ci;
    MrEggNoodle
        10
    MrEggNoodle  
       2015-07-27 10:20:23 +08:00
    一直用mysql存中文没问题。四楼可以解决问题。
    sinux
        11
    sinux  
       2015-07-27 10:41:40 +08:00
    mariaDB,直接建表,没指定字符集,django 1.8.3, python3 完全没有这个问题。
    hayao650
        12
    hayao650  
       2015-07-27 18:57:04 +08:00 via iPad
    把表的字符集和字段的字符集都改成u8可破
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5418 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 57ms · UTC 08:36 · PVG 16:36 · LAX 01:36 · JFK 04:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.