0

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.

2
  • The error message does tell you what the problem is, you need to install a newer python library. Commented Oct 13, 2020 at 23:27
  • I have did it already but it didn't worked again Commented Oct 15, 2020 at 11:19

2 Answers 2

1

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()
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.