推荐学习书目
› 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 · Jul 26, 2015 · 8933 views
    This topic created in 4127 days ago, the information mentioned may be changed or developed.

    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 replies  •  2015-07-27 18:57:04 +08:00
    ciba1990
    ciba1990
    OP
    Jul 26, 2015
    1
    数据库是mariadb,是不是数据库设置有问题。
    ciba1990
    ciba1990
    OP
    Jul 26, 2015
    2
    英文就一点问题没有,奇了怪了。
    lixia625
    lixia625
    Jul 26, 2015
    3
    "\xE6\x94\xB9\xE7\xAB\xAF".decode('utf8')
    virusdefender
    virusdefender
    Jul 26, 2015
    4
    你怎么创建的数据库?

    create database xxx default character set utf-8;

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

    create database xblog default charset utf8 collate utf8_general_ci;
    MrEggNoodle
    MrEggNoodle
    Jul 27, 2015
    10
    一直用mysql存中文没问题。四楼可以解决问题。
    sinux
    sinux
    PRO
    Jul 27, 2015
    11
    mariaDB,直接建表,没指定字符集,django 1.8.3, python3 完全没有这个问题。
    hayao650
    hayao650
    Jul 27, 2015 via iPad
    12
    把表的字符集和字段的字符集都改成u8可破
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2532 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 11:57 · PVG 19:57 · LAX 03:57 · JFK 06:57
    ♥ Do have faith in what you're doing.