django+mysql

Posted shuaimeng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了django+mysql相关的知识,希望对你有一定的参考价值。

报错误:mysqlclient 1.3.13 or newer is required; you have 0.9.3

第一种:
django降到2.1.4版本就OK了

第二种(仍使用django 2.2版本):

找到python环境下的/site-packages/django/db/backends/mysql/base.py

# 找到base.py文件,注释掉 base.py 中如下部分(35/36行) 
if version < (1, 3, 3):
raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)

此时仍会会报错,报错信息如下:

AttributeError: ‘str’ object has no attribute ‘decode’

#找到operations.py文件(46行,版本不同行数不同哈~自个儿find一下),将decode改为encode #linux vim 查找快捷键:?decode 
if query is not None:
query = query.decode(errors=‘replace‘)
return query
#改为
if query is not None:
query = query.encode(errors=‘replace‘)
return query

 

以上是关于django+mysql的主要内容,如果未能解决你的问题,请参考以下文章

Django操作数据库

Django 链接MySQL及数据操作

Django:模型(model)和数据库(mysql)

mysql服务开着,但是django却连不上

django与mysql数据库基本操作

django与mysql数据库基本操作