My 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 FilesPython38libsite-packagessqlserver_adobase.py", line
13, in <module>
from . import dbapi as Database
File "C:Program FilesPython38libsite-packagessqlserver_adodbapi.py", lin
e 45, in <module>
from django.utils import six
ImportError: cannot import name 'six' from 'django.utils' (C:Program FilesPyth
on38libsite-packagesdjangoutils__init__.py)
根据这一建议,
我打开"C:\Program Files\Python38\lib\site-packages\sqlserver_ado\dbapi.py"并将"from django.utils import six
"更改为"import six
",并将六个模块升级到最新版本。
这次又提出了一个错误:
......
File "C:Program FilesPython38libsite-packagesdjangodbutils.py", line 20
7, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:Program FilesPython38libsite-packagesdjangodbutils.py", line 11
1, in load_backend
return import_module('%s.base' % backend_name)
File "C:Program FilesPython38libimportlib__init__.py", line 127, in impor
t_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:Program FilesPython38libsite-packagessqlserver_adobase.py", line
13, in <module>
from . import dbapi as Database
File "C:Program FilesPython38libsite-packagessqlserver_adodbapi.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/
这个包同时支持 Django2.2 和 Django 3.0,这是撰写本文时目前支持的版本。