Django 3.x error: 'mysql.connector.django' isn't an available database backend
Asked Answered
R

3

8

Having recently upgraded a Django project from 2.x to 3.x, I noticed that the mysql.connector.django backend (from mysql-connector-python) no longer works. The last version of Django that it works with is 2.2.11. It breaks with 3.0. I am using mysql-connector-python==8.0.19.

When running manage.py runserver, the following error occurs:

django.core.exceptions.ImproperlyConfigured: 'mysql.connector.django' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
    'mysql', 'oracle', 'postgresql', 'sqlite3'

I am aware that this is not an official Django backend but I have to use it on this project for reasons beyond my control.

I am 80% sure this is an issue with the library but I'm just looking to see if there is anything that can be done to resolve it beyond waiting for an update.

UPDATE:

mysql.connector.django now works with Django 3+.

Rakish answered 30/3, 2020 at 9:4 Comment(2)
which version of python are you using?Iwo
I am using Python 3.7.Rakish
F
5

For Django 3.0 and Django 3.1 I managed to have it working with mysql-connector-python 8.0.22. See this https://dev.mysql.com/doc/relnotes/connector-python/en/news-8-0-22.html.

Fillian answered 16/6, 2021 at 14:24 Comment(5)
I tried the latest version a while ago and it imports from django.db.backends.mysql.base, which requires mysqlclient. The old version of mysql-connector-python didn't. I can't use mysqlclient in this one particular project. Please correct me if wrong.Rakish
There is no mysqlclient in the pipfile of the project I was working on.Fillian
In my case when I tried Django 3.2 and mysql-connector-python 8.0.25 it complained that I didn't have mysqlclient installed. It looks like the mysqlclient requirement was added after 8.0.22 in this commit when they now import django.db.backends.mysql.base: github.com/mysql/mysql-connector-python/commit/…Rakish
Using Django 3.1 is not an option?Fillian
I guess so, just not ideal that support drops off after that. Anyway, I'll update the accepted answer seeing as yours is now most relevant.Rakish
N
2

Connector/Python still supports Python 2.7, which was dropped by Django 3. We are currently working on adding support for Django 3, stay tunned.

Neustria answered 8/4, 2020 at 14:54 Comment(8)
Is there any place that this can be tracked? I filed a bug report a while ago but it has not been acknowledged yet: bugs.mysql.com/bug.php?id=99106Rakish
Yes. There's a contribution that we are working on. See bugs.mysql.com/bug.php?id=99069 This bug will also be updated.Neustria
These bug reports seem to have gone pretty quiet.Rakish
@Rakish they will be updated once the work is released. Which will be soon.Neustria
mysql.connector.django now works with Django 3+, however, it also now requires that you use mysqlclient as it imports from django.db.backends.mysql.base as opposed to django.db.backends.base.base as previously. In one project I cannot use mysqlclient (my reason for using the connector in the first place), so this problem remains.Rakish
Correct. But that was fixed in 8.0.26, it doesn't have the dependency anymore (Bug #32947160). See dev.mysql.com/doc/relnotes/connector-python/en/news-8-0-26.htmlNeustria
I'm not able to test this at the moment but it is good to know for future!Rakish
Confirming that 8.0.26-8.029 work as expected, however >= 8.0.30 I get database errors when running locally (weirdly, it works on the live server).Rakish
H
-2

in settings.py change database engine this way 'ENGINE': 'django.db.backends.mysql'

Horatio answered 27/5, 2022 at 6:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.