skip to Main Content

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

Answers


  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.

    Login or Signup to reply.
  2. 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()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search