Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Connector/Python as Django Engine?

Can't find an answer for this even after hours and hours of googling & searching stack overflow. I assure you I've seen all answers that could be deemed relevant and none of those have solved the issue I'm facing. Without further ado -

currently in shell I can do this:

Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
[GCC 5.3.1 20160413] on linux2
Type "help", "copyright", "credits" or "license" for more information. 
>>> from distutils.sysconfig import get_python_lib
>>> print get_python_lib()
/usr/lib/python2.7/dist-packages
>>> import mysql.connector
>>> db = mysql.connector.connect(user='root', password='test123', host='127.0.0.1', database='mydb')
>>> db
<mysql.connector.connection.MySQLConnection object at 0x7fd3a80536d0>

verifying that I have this module installed. However when I try to go to the settings.py file to set DATABASE ENGINE to be

DATABASES = {
    'default': {
        'ENGINE': 'mysql.connector.django',
        'NAME': 'mydb',
        'USER': 'root',
        'PASSWORD': 'test123',
        'HOST': '127.0.0.1',
        'PORT': '3306'
    }
}

and try to start my server i keep getting the error:

django.core.exceptions.ImproperlyConfigured: 'mysql.connector.django'
isn't an available database backend.

not sure how to fix this. I'm on Django version 1.9.7, Python version shown in code snippet above

What would be the difference between using 'mysql.connector.django' vs. using 'django.db.backends.mysql' ?

like image 385
omgirok Avatar asked Oct 31 '22 01:10

omgirok


1 Answers

Here is my successful solution after one day's searching: install the following packages first

django==2.2.15
mysql-connector-python==8.0.23
django-mysql==3.9.0

Then you can configure in settings file

DATABASES = {
    'default': {
        'ENGINE': 'mysql.connector.django',
        'NAME': 'mydb',
        'USER': 'root',
        'PASSWORD': 'test123',
        'HOST': '127.0.0.1',
        'PORT': '3306'
    }
}
like image 199
Jerry An Avatar answered Nov 15 '22 06:11

Jerry An