Bug #86105 mysql-connector-python fails to work with django 1.11

Submitted: 27 Apr 2017 9:11 Modified: 28 Jul 2017 2:18
Reporter: Michael Martin Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version:2.1.6 OS:Ubuntu
Assigned to: CPU Architecture:Any
Tags: connector, Django, python

[27 Apr 2017 9:11] Michael Martin
Description:

I installed on ubuntu 16.04 django 1.11 usinf pip3 and then installed the oracle mysql-connector-python.  When I try to use the driver with django I get the error below.

from django.db import models
Traceback (most recent call last):
  File "/home/django/workspace/mysite/manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/django/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/home/django/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 337, in execute
    django.setup()
  File "/home/django/.local/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/django/.local/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models()
  File "/home/django/.local/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/django/.local/lib/python3.5/site-packages/django/contrib/auth/models.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/home/django/.local/lib/python3.5/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
    class AbstractBaseUser(models.Model):
  File "/home/django/.local/lib/python3.5/site-packages/django/db/models/base.py", line 124, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/home/django/.local/lib/python3.5/site-packages/django/db/models/base.py", line 330, in add_to_class
    value.contribute_to_class(cls, name)
  File "/home/django/.local/lib/python3.5/site-packages/django/db/models/options.py", line 214, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/home/django/.local/lib/python3.5/site-packages/django/db/__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/home/django/.local/lib/python3.5/site-packages/django/db/utils.py", line 212, in __getitem__
    conn = backend.DatabaseWrapper(db, alias)
  File "/home/django/.local/lib/python3.5/site-packages/mysql/connector/django/base.py", line 336, in __init__
    super(DatabaseWrapper, self).__init__(*args, **kwargs)
  File "/home/django/.local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 96, in __init__
    self.client = self.client_class(self)
TypeError: 'NoneType' object is not callable
Finished "/home/django/workspace/mysite/manage.py migrate" execution.

How to repeat:
On ubuntu 16.04 install django 1.11
pip install django
pip3 install --egg http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.6.zip

create a django project and create a app 
Follow steps in tutorial
https://docs.djangoproject.com/en/1.11/intro/tutorial01/

create a database in mysql

configure database settings
In the settings.py file

DATABASES = {
    'default': {
        'NAME': 'mysite',
        'ENGINE': 'mysql.connector.django',
        'USER': 'mysql_user',
        'PASSWORD': 'priv4te',
        'OPTIONS': {
          'autocommit': True,
        },
    }
}

 

run migrations command from the root of the project
python3 manage.py migrate
[27 Apr 2017 9:56] Chiranjeevi Battula
Hello Michael Martin,

Thank you for the bug report.
Verified as described with the help of dev's.

Thanks,
Chiranjeevi.
[27 Apr 2017 10:07] Michael Martin
I mistype a command in my steps, I user pip3 to install django.
[28 Jul 2017 2:18] Paul DuBois
Posted by developer:
 
Fixed in 2.1.7.

Connector/Python is now compatible with Django 1.11.
[17 Aug 2017 5:01] Brad Smith
When is version 2.1.7 going to be available?  Here's what I get when I try to get 2.1.7:

brad$ pip install mysql-connector==2.1.7
Collecting mysql-connector==2.1.7
  Could not find a version that satisfies the requirement mysql-connector==2.1.7 (from versions: 2.1.3, 2.1.4, 2.1.6, 2.2.3)
No matching distribution found for mysql-connector==2.1.7

** and 2.2.3 does not install at all.  I am using Python version 3.6.2.
[2 Dec 2017 8:38] Saurabh Mishra
I had the same problem and was using exact same configuration. So. First I was trying mysqlclient but it didn't work so I installed mysql-connector==2.1.6 and surprisingly it was also not working with Django1.11 so I did some research on google and found the solution.

If >>> you are facebook user login and visit https://www.facebook.com/groups/python.django/permalink/1657026527681920/

Else >>>

1) activate your virtualenv.

2) pip3 install mysql-connector==2.1.6

3) visit: https://github.com/mysql/mysql-connector-python/tree/master/lib/mysql/connector/django ...and download base.py for django1.11.

4) Now, go to your env's lib/python(version)/site-packages/mysql/connector/django and replace base.py with downloaded base.py downloaded previously.

Enjoy Django!

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.056 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.