0

enter image description here

Can someone please explain what exactly is this error and what should i do? Because i have tried updating mysql on my laptop to get rid of the error but it still says the same

updated mysql, still no change

1 Answers1

0

Try to install the minimum required version of mysqlclient or newer

pip install mysqlclient==1.4.3

OR

pip install mysqlclient

MySQL and mysqlclient are different MySql is the database itself and mysqlclient is the client used to access the database


EDIT: Create a Virtual Environment to isolate your project required dependencies

1 Install virtual Environment to isolate your project To create a virtual env:

  1. Create a new directory to stock your virtual environment :

c:\my_virtual_env

  1. create the virtual env:

cd C:\my_virtual_env "C:\my_virtual_env" py -m venv database_project_venv"

2 Activate the virtual environment

C:\my_virtual_env\database_project_venv\Scripts\activate

You should have something like that displayed in your terminal :

(database_project_venv) c:\my_virtual_env

To deactivate the virtual environment use the command deactivate. For example: (database_project_venv) c:\database_project_11>> deactivate

3 Install Django

Still in your virtual environment, install Django:

1. Upgrade pip : `(database_project_venv) c:\database_project_1> python -m pip install --upgrade pip`

2. Install Django: `(database_project_venv) c:\database_project_1> pip install django`

3. Check django Version : `(database_project_venv) c:\database_project_1> django-admin --version`

4 Create your Django project

(database_project_venv) c:\> cd C:\database_project_1 
(database_project_venv) c:\database_project_1> django-admin startproject database_project 

You should have something like this

c:\database_project_1\database_project\

5 Create you app

(database_project_venv) c:\database_project_1> cd database_project
(database_project_venv) c:\database_project_1\database_project> python manage.py startapp my_app

Configure your settings.py by adding your app to the in INSTALLED_APPS

INSTALLED_APPS = [
…
    'my_app.apps.MyAppConfig',
…
]

6 Configure your MySql

In settings.py, configure your database

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'DB_NAME',
        'USER': 'DB_USER',
        'PASSWORD': 'DB_PASSWORD',
        'HOST': 'localhost', # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}

7 Database initialization

(database_project_venv) c:\database_project_1\database_project> python manage.py makemigrations
(database_project_venv) c:\database_project_1\database_project> python manage.py migrate

8 Create SuperUser (database_project_venv) c:\database_project_1\database_project> python manage.py createsuperuser

Update your project as needed

Now install your mysqlclient

(database_project_venv) c:\database_project_1\database_project> pip install mysqlclient

Try to run your project

(database_project_venv) c:\database_project_1\database_project> python manage.py runserver

Tell if everything works correctly now

Philippe Sisowath
  • 1,400
  • 1
  • 6
  • 11
  • i did what you asked me to and it gave this message : https://imgur.com/lGPmWOi however when i tried to run the file, it gave me this error : https://imgur.com/ANOp1Mm so i tried the first code you asked me to run but it gave some other error : https://imgur.com/twKUkg4 I'm sorry if this is a lot but i really need to rectify this for a project i have to submit in 4 days – Disha Shetty Apr 25 '23 at 04:31
  • From your screenshot, it seems that you have environment configuration conflicts and the installed application are not correctly detected. Furthermore you're not using virtual environment. I'll edit my answer to help you install a Django project with Virtualenv. Please tell me if it solves the problem. – Philippe Sisowath Apr 25 '23 at 05:58
  • i followed the steps in your comment and in the database initialization part when i run the first command : "python manage.py makemigrations" it gives me the following error: https://imgur.com/EtPYTzg (this is the error i got the second time i tried to do everything from the beginning, following your steps. the first time when i tried this and i got the error, instead of doing the database initialization, i first did pip install mysqlclient and then did the database initialization, however that time, it gave the same error saying i have the old version of mysqlclient and needed to update) – Disha Shetty Apr 25 '23 at 14:24
  • okay so i think its fine, cuz its up and running now. i searched up for why i was getting the same error always and finally found a stack overflow post : https://stackoverflow.com/questions/55657752/django-installing-mysqlclient-error-mysqlclient-1-3-13-or-newer-is-required/59591269#59591269 This comment cleared it out. Nevertheless, thank you so much for taking your time and helping me out !! – Disha Shetty Apr 25 '23 at 14:51
  • Really glad I was able to help you. Good luck for you project. – Philippe Sisowath Apr 25 '23 at 15:45