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

新创建django项目,配置mysql 报错:报错:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

配置:

settings.py配置默认数据库

"default":{
    "ENGINE": "django.db.backends.mysql",
    "NAME": "xx",
    "USER": "root",
    "PASSWORD": "xx",
    "HOST": "localhost",
    "PORT": "3306",
    # 'OPTIONS': {
    #     # "init_command": "SET foreign_key_checks = 0;",
    #     "init_command": "SET FOREIGN_KEY_CHECKS=0;",
    # }
},

__init__.py(和settings.py同一目录)

import pymysql
pymysql.install_as_MySQLdb()

执行数据迁移,报错:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

解决:

第一种:把django版本降低

第二种:根据报错提示

1. 找到django\db\backends\mysql安装的目录,我的环境是一个项目一个环境,即venv:

项目根路径\venv\Lib\site-packages\django\db\backends\mysql

2. 打开base.py文件,并找到以下代码

version = Database.version_info

在if中加入pass,并注释以下代码

raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

如:

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

然后保存并关闭文件。

3. 打开 operations.py文件

找到以下代码:

query = query.decode(errors='replace')

将decode更改为encode,如下所示

query = query.encode(errors='replace')

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值