pythondjangodjango-mssqldjango-mssql-backend

AttributeError: module 'six' has no attribute 'memoryview' occurs when configuring django database for django-mssql


My Django is the latest version, python3.8. I want to configure the database for sql server 2008 R2, so I install django-mssql(aka,sqlserver_ado). After running the server, an error occurs:

  .........
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Program Files\Python38\lib\site-packages\sqlserver_ado\base.py", line
 13, in <module>
    from . import dbapi as Database
  File "C:\Program Files\Python38\lib\site-packages\sqlserver_ado\dbapi.py", lin
e 45, in <module>
    from django.utils import six
ImportError: cannot import name 'six' from 'django.utils' (C:\Program Files\Pyth
on38\lib\site-packages\django\utils\__init__.py)

Following this suggestion,

I open "C:\Program Files\Python38\lib\site-packages\sqlserver_ado\dbapi.py" and change "from django.utils import six" to "import six" , as well as upgrading the six module to latest version.

And this time another Error raised:

......
  File "C:\Program Files\Python38\lib\site-packages\django\db\utils.py", line 20
7, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "C:\Program Files\Python38\lib\site-packages\django\db\utils.py", line 11
1, in load_backend
    return import_module('%s.base' % backend_name)
  File "C:\Program Files\Python38\lib\importlib\__init__.py", line 127, in impor
t_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Program Files\Python38\lib\site-packages\sqlserver_ado\base.py", line
 13, in <module>
    from . import dbapi as Database
  File "C:\Program Files\Python38\lib\site-packages\sqlserver_ado\dbapi.py", lin
e 750, in <module>
    Binary = six.memoryview
AttributeError: module 'six' has no attribute 'memoryview'

I check the six module, and yes, it doesn't include a single word named "memoryview". But why the dbapi.py include the code "Binary = six.memoryview"? And I search "six.memoryview" on Google.So many results but I can't understand.


Solution

  • The django-mssql package hasn't been updated in years, and will not work with any currently supported version of Django. The package you will want to use for current versions of Django is django-mssql-backend:

    https://pypi.org/project/django-mssql-backend/

    This package supports both Django 2.2, and Django 3.0, the currently supported versions as of this writing.