Reputation: 35
I am using Django 3.1.0
and I get the error below when I set MySQL
as a database on production server.
#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
My server is an apache server
and uses Cpanel
and it is a python server, not a vps one.
I have tried installing mysqlclient
and PyMySQL
and adding the below code to the __init__.py
file.
import pymysql
pymysql.version_info = (1, 3, 13, "final", 0)
pymysql.install_as_MySQLdb()
and it is my DB config is Django
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'sadraedu_mydb',
'USER': 'sadraedu_mydbu',
'PASSWORD': '*******',
'HOST': 'localhost',
'PORT': '3306',
}
}
Any help would be appreciated.
Upvotes: 0
Views: 1073
Reputation: 2894
This error occurs because you are using PyMySQL as a replacement for mysqlclient (it's one or the other, you don't need both)
Django officially supports mysqlclient, but not PyMySQL (at time of writing, Dec 2020, Django 3.1)
Django has a check for the version of mysqlclient that you are using.
If you use PyMySQL as a replacement, it uses a completely different numbering system.
That's what causes this error.
"mysqlclient 1.4.0 or newer is required; you have 0.10.1."
In this example, it is telling you that it requires mysqlclient 1.4.0. But you are using pymysql 0.10.1.
If you want to use pymysql anyway, you need to fake the version number to bypass this error.
For example, when you set up pymysql as your drop-in replacement:
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()
Upvotes: 1
Reputation: 1
I had the same issue deploying my Django local app to Google Cloud.
Using Django 3.0 instead resolved the issue for me:
pip install Django==3.0
For some reason it did not recognise en-uk for LANGUAGE_CODE
in settings.py
, so I had to change that, but that was the only thing.
Upvotes: 0