在 Django 中使用 MySQL 作为数据库时出错
Getting error while using MySQL as database in django
我正在使用 Django 3.1.0
,当我将 MySQL
设置为 生产服务器 .
上的数据库时出现以下错误
#ERROR
Getting django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; you have 0.10.1. error while using MySQL in Django
我的服务器是 apache server
并使用 Cpanel
,它是 python 服务器,而不是 vps 服务器.
我已尝试安装 mysqlclient
和 PyMySQL
并将以下代码添加到 __init__.py
文件中。
import pymysql
pymysql.version_info = (1, 3, 13, "final", 0)
pymysql.install_as_MySQLdb()
我的数据库配置是 Django
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'sadraedu_mydb',
'USER': 'sadraedu_mydbu',
'PASSWORD': '*******',
'HOST': 'localhost',
'PORT': '3306',
}
}
如有任何帮助,我们将不胜感激。
我在将 Django 本地应用程序部署到 Google 云时遇到了同样的问题。
改用 Django 3.0 解决了我的问题:
pip install Django==3.0
出于某种原因,它无法识别 settings.py
中 LANGUAGE_CODE
的 en-uk,所以我不得不更改它,但这是唯一的事情。
出现此错误是因为您正在使用 PyMySQL 替代 mysqlclient(这是一个或另一个,您不需要两者)
Django 正式支持 mysqlclient,但不支持 PyMySQL(在撰写本文时,2020 年 12 月,Django 3.1)
Django 会检查您正在使用的 mysqlclient 版本。
如果您使用 PyMySQL 作为替代,它使用完全不同的编号系统。
这就是导致此错误的原因。
“需要 mysqlclient 1.4.0 或更新版本;您有 0.10.1。”
在这个例子中,它告诉你它需要mysqlclient 1.4.0。但是你使用的是 pymysql 0.10.1.
如果你仍然想使用pymysql,你需要伪造版本号来绕过这个错误。
例如,当您将 pymysql 设置为直接替代时:
import pymysql
# because Django has a hard-coded check for mysqlclient version
# but we're using pymysql instead
pymysql.version_info = (1, 4, 0, "final", 0)
pymysql.install_as_MySQLdb()
我正在使用 Django 3.1.0
,当我将 MySQL
设置为 生产服务器 .
#ERROR
Getting django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; you have 0.10.1. error while using MySQL in Django
我的服务器是 apache server
并使用 Cpanel
,它是 python 服务器,而不是 vps 服务器.
我已尝试安装 mysqlclient
和 PyMySQL
并将以下代码添加到 __init__.py
文件中。
import pymysql
pymysql.version_info = (1, 3, 13, "final", 0)
pymysql.install_as_MySQLdb()
我的数据库配置是 Django
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'sadraedu_mydb',
'USER': 'sadraedu_mydbu',
'PASSWORD': '*******',
'HOST': 'localhost',
'PORT': '3306',
}
}
如有任何帮助,我们将不胜感激。
我在将 Django 本地应用程序部署到 Google 云时遇到了同样的问题。
改用 Django 3.0 解决了我的问题:
pip install Django==3.0
出于某种原因,它无法识别 settings.py
中 LANGUAGE_CODE
的 en-uk,所以我不得不更改它,但这是唯一的事情。
出现此错误是因为您正在使用 PyMySQL 替代 mysqlclient(这是一个或另一个,您不需要两者)
Django 正式支持 mysqlclient,但不支持 PyMySQL(在撰写本文时,2020 年 12 月,Django 3.1)
Django 会检查您正在使用的 mysqlclient 版本。
如果您使用 PyMySQL 作为替代,它使用完全不同的编号系统。
这就是导致此错误的原因。
“需要 mysqlclient 1.4.0 或更新版本;您有 0.10.1。”
在这个例子中,它告诉你它需要mysqlclient 1.4.0。但是你使用的是 pymysql 0.10.1.
如果你仍然想使用pymysql,你需要伪造版本号来绕过这个错误。
例如,当您将 pymysql 设置为直接替代时:
import pymysql
# because Django has a hard-coded check for mysqlclient version
# but we're using pymysql instead
pymysql.version_info = (1, 4, 0, "final", 0)
pymysql.install_as_MySQLdb()