7

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+.

alstr
  • 1,107
  • 14
  • 27

3 Answers3

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.

obotezat
  • 906
  • 13
  • 18
  • 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. – alstr Jun 16 '21 at 15:39
  • 1
    There is no `mysqlclient` in the pipfile of the project I was working on. – obotezat Jun 17 '21 at 08:48
  • 1
    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`: https://github.com/mysql/mysql-connector-python/commit/407ac56ad770322d43acafc5c18622b79bc63d96#diff-021c9eb7e40afc07c92a0503ab973f4b5d9ad34310cd3021ed926d7da0a9e027 – alstr Jun 18 '21 at 11:12
  • 1
    Using `Django 3.1` is not an option? – obotezat Jun 21 '21 at 08:38
  • 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. – alstr Jun 21 '21 at 17:48
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.

Nuno Mariz
  • 412
  • 2
  • 7
  • Is there any place that this can be tracked? I filed a bug report a while ago but it has not been acknowledged yet: https://bugs.mysql.com/bug.php?id=99106 – alstr Apr 17 '20 at 17:16
  • 1
    Yes. There's a contribution that we are working on. See https://bugs.mysql.com/bug.php?id=99069 This bug will also be updated. – Nuno Mariz Apr 20 '20 at 13:12
  • These bug reports seem to have gone pretty quiet. – alstr Jul 28 '20 at 07:53
  • 1
    @alstr they will be updated once the work is released. Which will be soon. – Nuno Mariz Aug 18 '20 at 15:16
  • `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. – alstr Jun 09 '21 at 11:57
  • 1
    Correct. But that was fixed in 8.0.26, it doesn't have the dependency anymore (Bug #32947160). See https://dev.mysql.com/doc/relnotes/connector-python/en/news-8-0-26.html – Nuno Mariz Nov 23 '21 at 09:19
  • I'm not able to test this at the moment but it is good to know for future! – alstr Nov 24 '21 at 12:18
-1

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