关于使用Django迁移数据库时遇到的报错

Django


最近在使用Django迁移数据库时,遇到了一个问题。
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
下面我们就来解决它,因为Django版本不一样,少许有些不一样,先说明下环境

  • Python:3.7.3
  • Django:3.0.1
  • PyMySQL:0.9.3

在执行python manage.py mirgate迁移数据库时,会报如下错误
在这里插入图片描述

django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

网上查找了一些资料,基本上可以定义为django内部的一个版本限制在作怪
对就是它:
在这里插入图片描述

 if version < (1, 3, 13):
     raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

根据你Django的目录找到base.py文件(在site packages里可以找到django目录),注释掉这两行代码!!

==例如:… /lib/python3.7/site-packages/django/db/backends/mysql ==

在这里插入图片描述
在这里就大功告成,妥妥的!
重新执行python manage.py migrate迁移数据库
在这里插入图片描述
写在后面的话:因为我用的是Django3.0.1版本,没有出现网上其他人出现的后续问题。

File "/usr/local/bin/Python37/lib/site-packages/django/db/backends/mysql/operations.py", line 146, in last_executed_query
    query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'

根据提示打开上图位置所说位置将代码中的decode改为encode就可以了。

def last executed query(self, cursor, sql, params):
# With MysQLdb, cursor objects have an(undocumented) executed
# attribute where the exact query sent to the database is saved.
# See MySQLdb/ cursors. py in the source distribution.
query= getattr(cursor, '_executed', None)
if query is not None:
	query= query.encode(errors='replace')
return query
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值