python3.7django2.2mysql异常
错误日志
mysqlclient 1.3.13 or newer is required;
python">File "/Users/huoyinghui/workspaces/drf3/lib/python3.7/site-packages/django/db/utils.py", line 201, in __getitem__ backend = load_backend(db["ENGINE"])
File "/Users/huoyinghui/workspaces/drf3/lib/python3.7/site-packages/django/db/utils.py", line 110, in load_backend
return import_module("%s.base" % backend_name)
File "/Users/huoyinghui/workspaces/drf3/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/huoyinghui/workspaces/drf3/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 36, in <module>
raise ImproperlyConfigured("mysqlclient 1.3.13 or newer is required; you have %s." % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
原因是使用了pymysql, pymysql PyMySQL==0.9.3
django.db.backends.mysql.base.py 版本限制了1.3.13 以上;
django 2.2.7 做了限制.
pymysql.init.py中替换了MySQLdb
VERSION = (0, 9, 3, None) #pymysql 库版本
if VERSION[3] is not None:
VERSION_STRING = "%d.%d.%d_%s" % VERSION
else:
VERSION_STRING = "%d.%d.%d" % VERSION[:3]
def get_client_info(): # for MySQLdb compatibility
version = VERSION
if VERSION[3] is None:
version = VERSION[:3]
return ".".join(map(str, version))
connect = Connection = Connect
# we include a doctored version_info here for MySQLdb compatibility
version_info = (1, 3, 12, "final", 0) # 覆盖MySQLdb的版本, 与django2.2 版本冲突
NULL = "NULL"
__version__ = get_client_info()
def install_as_MySQLdb():
"""
After this function is called, any application that imports MySQLdb or
_mysql will unwittingly actually use pymysql.
"""
sys.modules["MySQLdb"] = sys.modules["_mysql"] = sys.modules["pymysql"]
该问题的github issue
该问题在django orm层处理
因此,我建议在django3.0发布前,我们应该使用django2.0, 避免str/byte的问题,等3.0发布后,我们直接升级django到3.0即可。在此之前,我们的代码只要兼容django3.0就行。与pymysql无关。
以上是 python3.7django2.2mysql异常 的全部内容, 来源链接: utcz.com/z/510940.html