当前位置:Gxlcms > mysql > djangoadmin–mysql编码问题报错_MySQL

djangoadmin–mysql编码问题报错_MySQL

时间:2021-07-01 10:21:17 帮助过:18人阅读

Django

bitsCN.com

重新restore了mysql到另一台机器上,今天新写了一个app,发现在admin界面下一添加汉字就会报错如下:

Warning at /admin/assets/add/Incorrect string value: '/xE5/x93/x88/xD5/x92/x88...' for column 'Name' at row 1Request Method:	POSTRequest URL:	http://127.0.0.1:8000/admin/assets/add/Django Version:	1.2.3Exception Type:	WarningException Value:	Incorrect string value: '/xE5/x93/x88/xD5/x92/x88...' for column 'Name' at row 1Exception Location:	/usr/lib/pymodules/python2.7.1/MySQLdb/cursors.py in _warning_check, line 82Python Executable:	/usr/bin/pythonPython Version:	2.7.1

初步判断 应该是mysql的问题 [代研究本质问题]:

在my.ini 添加如下:

[client]character-set-client = utf8default-character-set = utf8[mysqld]character-set-server = utf8character-set-filesystem = utf8[mysql]init_connect='SET NAMES utf8'[mysql]default-character-set=utf8

重启mysql服务器,问题解决。

 

-------------------------------------------------------------------------------------

 

查看创建mysql数据库的默认编码:

show create database db_name;

更改已经创建的db的编码:

alter database db_name character set utf8 collate utf8_general_ci;

查看数据库相关信息:

mysql>status

查看数据库相关信息2:

mysql> show variables like’char%’;
bitsCN.com

人气教程排行