当前位置:   article > 正文

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

django.db.utils.notsupportederror: mysql 8 or later is required (found 5.7.4

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

  1. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\base\base.py", line 330, in cursor
  2. return self._cursor()
  3. ^^^^^^^^^^^^^^
  4. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\base\base.py", line 272, in connect
  5. self.init_connection_state()
  6. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\mysql\base.py", line 257, in init_connection_state
  7. super().init_connection_state()
  8. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\base\base.py", line 239, in init_connection_state
  9. self.check_database_version_supported()
  10. 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
  11. raise NotSupportedError(
  12. 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

 

 

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号