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

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

我的Django是最新版本,python3.8。我想为 sql server 2008 R2 配置数据库,所以我安装了 django-mssql(aka,sqlserver_ado)。 运行服务器后,出现错误:

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

关注此

我打开"C:\Program Files\Python38\lib\site-packages\sqlserver_ado\dbapi.py"并将“from django.utils import six”更改为“import six”,并将六个模块升级到最新版本。

这次又出现了另一个错误:

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

我检查了六个模块,是的,它不包含一个名为 "memoryview" 的单词。但为什么 dbapi.py 包含代码“Binary = six.memoryview”?我在 Google.So 上搜索 "six.memoryview" 很多结果,但我无法理解。

django-mssql 软件包多年未更新,并且不能与任何当前支持的 Django 版本一起使用。当前版本的 Django 要使用的包是 django-mssql-backend:

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

此包支持 Django 2.2 和 Django 3.0,这是撰写本文时当前支持的版本。