django-pyodbc-azure 2.1.0.0 不支持 Django 2.1.0

django-pyodbc-azure 2.1.0.0 not supporting Django 2.1.0

我们正在尝试将 Django-2.1 与 MS SQL Server 2012 连接。我们正在寻找用于此目的的模块,偶然发现了 django-pyodbc-azure。我们 pip 安装它并在重新启动应用程序时,我们收到以下错误消息:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper
 at 0x0000006140CB2BF8>
Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\django\utils\autoreload.py",
 line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\Program Files\Python36\lib\site-packages\django\core\management\comma
nds\runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "C:\Program Files\Python36\lib\site-packages\django\utils\autoreload.py",
 line 248, in raise_last_exception
    raise _exception[1]
  File "C:\Program Files\Python36\lib\site-packages\django\core\management\__ini
t__.py", line 337, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Program Files\Python36\lib\site-packages\django\utils\autoreload.py",
 line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\Program Files\Python36\lib\site-packages\django\__init__.py", line 24
, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Program Files\Python36\lib\site-packages\django\apps\registry.py", li
ne 112, in populate
    app_config.import_models()
  File "C:\Program Files\Python36\lib\site-packages\django\apps\config.py", line
 198, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Program Files\Python36\lib\importlib\__init__.py", line 126, in impor
t_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Program Files\Python36\lib\site-packages\django\contrib\auth\models.p
y", line 2, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "C:\Program Files\Python36\lib\site-packages\django\contrib\auth\base_use
r.py", line 47, in <module>
    class AbstractBaseUser(models.Model):
  File "C:\Program Files\Python36\lib\site-packages\django\db\models\base.py", l
ine 101, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "C:\Program Files\Python36\lib\site-packages\django\db\models\base.py", l
ine 304, in add_to_class
    value.contribute_to_class(cls, name)
  File "C:\Program Files\Python36\lib\site-packages\django\db\models\options.py"
, line 203, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length(
))
  File "C:\Program Files\Python36\lib\site-packages\django\db\__init__.py", line
 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "C:\Program Files\Python36\lib\site-packages\django\db\utils.py", line 20
2, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "C:\Program Files\Python36\lib\site-packages\django\db\utils.py", line 11
0, in load_backend
    return import_module('%s.base' % backend_name)
  File "C:\Program Files\Python36\lib\importlib\__init__.py", line 126, in impor
t_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Program Files\Python36\lib\site-packages\sql_server\pyodbc\base.py",
line 11, in <module>
    raise ImproperlyConfigured("Django %d.%d.%d is not supported." % VERSION[:3]
)
django.core.exceptions.ImproperlyConfigured: Django 2.1.0 is not supported.

我们尝试了很多 Django 版本,例如 2.x、2.0.4、2.1,所有版本似乎都抛出相同的错误,即

Django 2.x.x is not supported.

settings.py中的数据库信息:

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'HOST': 'xxxxxx,1433',
        'USER': 'xxxxxxxx',
        'PASSWORD': 'xxxxxxxx',
        'NAME': 'xxxxxx',
        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
            'host_is_server': True
        },
    }
}

如有任何线索,我们将不胜感激。谢谢

几个月前我遇到了同样的问题。最终的组合版本是 python 3.5django 1.11 以及 django-pyodbc-azure 最新版本

通过从 https://pypi.org/project/django-pyodbc-azure/#files 下载 django-pyodbc-azure 2.1.0.0wheel file 并使用命令 pip install django_pyodbc_azure-2.1.0.0-py3-none-any.whl.

安装解决了这个问题