Django报错记录
2020-05-20 本文已影响0人
LeslieFind
一、数据库相关
1.1、mysql数据库配置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_diff',
'USER': 'root',
'PASSWORD': '123456',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
1.2、Error loading MySQLdb module
报错信息:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
解决方案:
使用的是python3,下载pymysql:pip install PyMySQL
1.3、下载完依旧报Error loading MySQLdb module
报错信息:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
解决方案:
在项目的init.py增加:
import pymysql
pymysql.install_as_MySQLdb()
1.3、执行python manage.py migrate,依旧报错
报错信息:
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
解决方案:
在项目的init.py增加:pymysql.version_info=(1,3,13,"final",0)
项目init.py:
import pymysql
pymysql.version_info=(1,3,13,"final",0)
pymysql.install_as_MySQLdb()
mysql相关报错解决
1.4、中文字符格式问题,在admin页面修改'django-1366, "Incorrect string value: '\xE6\x88\x9A\xE4\xBC\x9F...'
报错信息:
django-1366, "Incorrect string value: '\xE6\x88\x9A\xE4\xBC\x9F...
解决方案:
1、根据帖子:https://www.cnblogs.com/qwj-sysu/p/5400705.html
mysql> show variables like "%char%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
mysql> set character_set_database='utf8';
Query OK, 0 rows affected (0.01 sec)
mysql> set character_set_database='utf8';
Query OK, 0 rows affected (0.01 sec)
但是去admin中修改还存在报错,于是找到帖子:https://www.jianshu.com/p/521ed0544110
ALTER TABLE Table_Name CONVERT TO CHARACTER SET gbk COLLATE gbk_chinese_ci;
问题解决!