mysqlclient 1.4.0 or newer is required; you have 0.10.0 error | solved

mysqlclient 1.4.0 or newer is required; you have 0.10.0__version__ – solved

Hi everyone,

        How to connect  mySQL database to Django on Cpanel.

Almost everyone gets the error when they want to deploy their Django application to the Cpanel and go to connect to the MySQL database through their Django app. This error is such a common error so I am gonna solve this error today in this tutorial so read this tutorial carefully.

So without any further delay let’s get started. First of all go to your file manager in Cpanel then go to your virtualenv folder then go to your domain folder after that 3.7 then lib on that folder you will find Python 3.7 to that folder after that site-packages then Django after that db after that backends then click on the mySQL folder to open it , after opening edit the file base.py 

Cpanel > virtualenv > domain folder > 3.7 > lib > Python 3.7 > site-packages > Django > db > backends > mySQL > base.py

there you will find the below code:

 

version = Database.version_info
if version < (1, 4, 0):
    raise ImproperlyConfigured('mysqlclient 1.4.0 or newer is required; you have %s.' % Database.__version__)

Head to the above code and replace it as the below.

version = Database.version_info
if version < (1, 4, 0):
    pass
'''
    raise ImproperlyConfigured('mysqlclient 1.4.0 or newer is required; you have %s.' % Database.__version__)
'''

Then go to your project main folder. Again go to your project named folder settings.py is. Edit the __init__.py file as the below code, save it and go back. 

Defaultly it will be blank, just copy and paste the code, and you are set .

import pymysql
pymysql.install_as_MySQLdb()

Now go to your Cpanel and click on MySQL databases then you will see create new database put your database name as you want. Then click on create database after that scroll down and there you will see MySQL users there you have to put your username , password , your password and then your password again

Note: that you have to remember your database name which you gave in creating a new database then you have to remember your username and password too. 

After typing username and password and password again click on create new user. After then scroll down and you see add user to database here you have to select your user name and database name which you gave before then click on add. The database has been created. So now you have to go to your file manager and head to your settings.py file. And Edit your settings.py file. Head where databases are declared, it will look like the below code :

DATABASES = {

 

 

        ‘ENGINE’: ‘django.db.backends.mysql’,

        ‘NAME’: ‘Name of your database’,

        ‘USER’: ‘username’,

        ‘PASSWORD’: ‘your database password’,

        ‘HOST’: ‘localhost’,

        ‘OPTIONS’: {

            ‘init_command’: “SET sql_mode=’STRICT_TRANS_TABLES'”

        }

    }

}

Note: here NAME will be the name of your database that you gave before. USER is the user of your database that you gave while creating the database.

PASSWORD will be your password while creating the database. And HOST is your host address. Generally it is localhost in some hostings it can change.

Now you have to go again to your Cpanel and scroll down where advanced settings are. Click on the terminal, then go to our terminal and activate your virtual environment. If you don’t know how to activate virtualenv in cpanel then see in the comment section there you will find the link to that tutorial . Then migrate your database using python manage.py migrate command. It will take some time based on your internet speed and your server speed.

Spread To Friends
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Comment