django2.2安装错误最全的解决方案(小结)

yipeiwu_com5年前Python基础

安装报错类型,解决方案;

1. 数据库连接报错

mysqldb只支持python2,pymysql支持3,都是使用c写的驱动,性能更好

# django中修改配置文件setting.py添加如下代码:

import pymysql
pymysql.install_as_MySQLdb()

解决方案:

修改数据库:mysqldb=>pymysql

2. 因为切换数据库导致版本错误

raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

解决方案:

注释掉检测数据库版本的代码

# "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 36, in <module>
 
# if version < (1, 3, 13):
#  raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

3. 切换数据库导致转码错误

"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/mysql/operations.py", line 146, in last_executed_query
    query = query.decode(errors='replace')

解决方案: ==暂时使用第二种类型==

修改decode为encode

把条件注释掉,防止出现不可预知的错误,这个错误很可能是python2中类型str和unicode的原因,python3中只有unicode类型数据

# "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/mysql/operations.py", line 146

 # if query is not None:
  #query = query.encode(errors='replace')

解决完成之后完美运行

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python Property属性的2种用法

假设定义了一个类:C,该类必须继承自object类,有一私有变量_x 复制代码 代码如下: class C:  def __init__(self):   self.__x=None  ...

Python合并字符串的3种方法

目的   将一些小的字符串合并成一个大字符串,更多考虑的是性能 方法    常见的方法有以下几种: 1.使用+=操作符 复制代码 代码如下:   BigString=small...

python 通过手机号识别出对应的微信性别(实例代码)

python 通过手机号识别出对应的微信性别,具体代码如下所述: def getGender(self,tel): self.d(resourceId="com.tencent....

浅谈Pandas 排序之后索引的问题

如下所示: In [1]: import pandas as pd ...: df=pd.DataFrame({"a":[1,2,3,4,5],"b":[5,4,3,2,1]})...

Python文件与文件夹常见基本操作总结

本文实例讲述了Python文件与文件夹常见基本操作。分享给大家供大家参考,具体如下: 1、判断文件(夹)是否存在。 os.path.exists(pathname) 2、判断路...