Django连接数据库报错内容及解决方法

1,执行python manage.py makemigrations

在这里插入图片描述

报错内容:
raise ImproperlyConfigured(‘mysqlclient 1.4.0 or newer is required; you have %s.’ % Database.version)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; you have 0.10.1.

主要是 因为MySQLclient 目前只支持到 Python3.4,我用了更高版本的 python3.7.4

解决办法:
在与项目同名的__init__.py文件下加一句:

pymysql.version_info = (1, 4, 13, “final”, 0) # 指定版本

在这里插入图片描述

2,执行python manage.py makemigrations,还报错

内容如下:
raise ImproperlyConfigured(‘mysqlclient 1.4.0 or newer is required; you have %s.’ % Database.version)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; you have 0.10.1.

在这里插入图片描述
解决办法:
在与项目同名的settings.py文件数据库的配置下加一句:

‘OPTIONS’: {‘isolation_level’: None}
在这里插入图片描述

再执行结果

在这里插入图片描述
这样就可以完成数据库的迁移了!

3,加了那句之后,数据库迁移出现错误如下

django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ((1064, “You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near ‘(6) NOT NULL)’ at line 1”))

意思是django2.1版本以上不支持mysql5.5
我降低django的版本改成了1.11.28,就好了。

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_46009608/article/details/111598602