I've trawled the forums but cannot find an answer or even any documentation on this. Trying to re-create a site like www.testandtrack.io
On running the command:
python manage.py inspectdb
I get the error:
mysqlclient 1.3.13 or newer is required; you have 0.9.3
I have tried all the suggested fixes including: -upgrading pip -installing a different wheel (32 bit instead of 64), namely mysqlclient-1.4.2-cp37-cp37m-win32.whl with the command pip install mysqlclient-1.4.2-cp37-cp37m-win32.whl (this works fine without an error but doesn't do the job required!)
My objective is to simply connect a legacy mysql database (running inside of XAMPP and myphpadmin) to Django. I've followed the documentation which misses out the need to install mysqlclient, and have got stuck at this point.
I guess your project uses pymysql instead of mysqlclient.
You can try to search the following code snippet in your project. If you find it, please try the following methods to fix this problem:
import pymysql
pymysql.install_as_MySQLdb()
Insert a line of code between these two to make it look like this:
import pymysql
pymysql.version_info = (1, 3, 13, "final", 0)
pymysql.install_as_MySQLdb()
Then try to start your project.
libssl-dev
has been installed before pip install mysqlclient
.This is how I fixed it.
Go to your django/db/backends/mysql installation dir. Check your path in the error message.
I'm using pipenv so my path is:
/home/username/.local/share/virtualenvs/project-env/lib/python3.7/site-packages/django/db/backends/mysql
If you use traditional env your path would be:
<env_directory_name>/Lib/site-packages/django/db/base.py
Open file base.py and search for:
version = Database.version_info
Put a pass inside if and comment line:
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.version)
Like this.
if version < (1, 3, 13):
pass
'''
raise ImproperlyConfigured(
'mysqlclient 1.3.13 or newer is required; you have %s.'
% Database.__version__
)
'''
Save, close this file and open operations.py.
Search for:
query = query.decode(errors='replace')
and change decode to encode
query = query.encode(errors='replace')
Now, try to run the server.
@edit
Until this answer, I found no other way to solve it. Today there are better ways to deal with this problem. This answer has a better approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With