django报错: raise NotSupportedError(django.db.utils.NotSupportedError: MySQL 8 or later is required

1、问题概述?

在django框架中使用ORM模型开发程序,执行

python manage.py makemigrations命令生成同步原语的时候,提示如下问题:

 raise NotSupportedError(

django.db.utils.NotSupportedError: MySQL 8 or later is required (found 5.7.43).

意思就是:需要MySQL 8或更高版本

但是在当前的企业环境中,大所数使用的还是mysql5.7相关版本。因为5.7之后的8.x版本是付费版本,不是用不起付费版,而是5.7更有性价比。贸然的更新数据库肯定是不合适的。

从图中也能够看出,base.py文件报错:

Line 239:in init_connection_state  初始化连接状态

Line 214:in check_database_version_supported 检查数据库版本支持

c5e4dfbcdaa247d3a06f6f5d86c5990d.png

  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\base\base.py", line 330, in cursor
    return self._cursor()
           ^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\base\base.py", line 272, in connect
    self.init_connection_state()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\mysql\base.py", line 257, in init_connection_state
    super().init_connection_state()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\base\base.py", line 239, in init_connection_state
    self.check_database_version_supported()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\base\base.py", line 214, in check_database_version_supported
    raise NotSupportedError(
django.db.utils.NotSupportedError: MySQL 8 or later is required (found 5.7.43).

 

2、解决办法

解决办法,要么修改自己的数据库版本为mysql8.x,要么让django不要检查。我们采用第二种方式。

第一步:找到base.py文件

我们可以直接搜索base.py文件,选中第一个

fc145e9347e2488fb24774709e376245.png

或者也可以搜索:check database version supported

43b93442e5d04dda8c0f73ca05e4d41d.png

上面的两种方式都可以找到base.py文件。

第二步:找到base.py中的239行,注解注释掉数据库检查就可以了。

e6a03be26d7e4eb795d6ee821d892b90.png

第三步:再次执行python manage.py makemigrations命令

从图中可以看出,模型创建成功

PS E:\pythonworkspace\mydjango_project>  python manage.py makemigrations
Migrations for 'accounts':
  accounts\migrations\0001_initial.py
    - Create model User
 

76c9f3d2affe47a7b4339301a87c5fb0.png

 

 

  • 12
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雾林小妖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值