skip to Main Content

I am trying to connnect MySQL to my django app. I keep on receive an error message suggesting me to install my SQL client first. When I run:

python manage.py runserver 

Here is the errro message I receive:

> (guessgame) Maiks-MBP:guessgame maiknoungoua$ python manage.py runserver
> Watching for file changes with StatReloader
> Exception in thread django-main-thread:
> Traceback (most recent call last):
> File "/Users/maiknoungoua/.local/share/virtualenvs/guessgame-o_cdbTdf/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
> import MySQLdb as Database
> ModuleNotFoundError: No module named 'MySQLdb'
> 

Can anyone help ?
Thanks in advance for the help.

I tried sourcing my export path in the bash profile

# Setting PATH for Python 3.9
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"
export PATH

export PATH=$HOME/omnetpp-5.6.2/bin:$HOME/omnetpp-5.2.1/tools/macosx/bin:$PATH
export QT_PLUGIN_PATH=$HOME/omnetpp-5.6.2/tools/macosx/plugins

alias ll='ls -lGaf'

export PATH="/usr/local/mysql/bin:$PATH"

2

Answers


  1. Chosen as BEST ANSWER

    Thank you for your answer it help a lot towards the resolution. When I ran that commannnd the output suggest some missing package that I was able to install. This issue can be considered resolved. I was able to install mysqlclient and to run my django server.


  2. For connection to the DBMS, Django ORM uses already existing modules (like psycopg2 for PostgreSQL or mysqlclient for MySQL in your case). So, whenever you are trying to connect to any kind of database, that Django supports, you also need to have corresponding module installed in your environment.

    To solve this problem, you need to install mysqlclient.

    For pip:

    pip install mysqlclient
    

    For poetry:

    poetry add mysqlclient
    

    For more information, you can look over official Github page

    P.S. If you are using python2, you need to use MySQL-python instead of mysqlclient

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search