Django admin interface Incorrect string value error Solution

Source: Internet
Author: User

The following error was found when adding Chinese characters on the django admin interface:

Warning at /admin/flatpages/flatpage/add/Incorrect string value: '\xE5\x93\x88\xE5\x93\x88...' for column 'content' at row 1Request Method:POSTRequest URL:http://127.0.0.1:8000/admin/flatpages/flatpage/add/Django Version:1.2.1Exception Type:WarningException Value:Incorrect string value: '\xE5\x93\x88\xE5\x93\x88...' for column 'content' at row 1Exception Location:/usr/lib/pymodules/python2.6/MySQLdb/cursors.py in _warning_check, line 82Python Executable:/usr/bin/pythonPython Version:2.6.6

There is no problem with adding English letters before. Check the mysql database encoding and find it is


Latin1_swedish_ci. Previously, phpmyadmin was used


"Create a database with the same name as the user and grant all permissions to the database created. I don't know how to change the default encoding when creating the database.

Solution: before the first syncdb operation, set the database


Utf8_genenal_ci or utf8_unicode (do not know the difference between them in processing Chinese characters ?).

You can use the following command to create a database:

GBK:CREATE DATABASE tinyCMS DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;

UTF8: CREATE DATABASE tinyCMS DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

When the table is created (but it does not affect the existing table ):

ALTER DATABASE tinyCMS CHARACTER SET utf8 COLLATE utf8_general_ci;

It is very important to specify the encoding when creating a mysql database. Many developers use the default encoding, but developing the encoding of the database can largely avoid the garbled problem caused by import and export.

We should follow the following standards: database, table, field and page or text encoding should be unified.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.