我们正尝试将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
},
}
}
任何线索都将不胜感激。谢谢。
答案 0 :(得分:1)
通过从https://pypi.org/project/django-pyodbc-azure/#files下载wheel file
的{{1}}并使用命令django-pyodbc-azure 2.1.0.0
进行安装,解决了此问题。
答案 1 :(得分:0)
几个月前,我遇到了同样的问题。最终的组合版本为python 3.5
和django 1.11
,最新版本为django-pyodbc-azure