Django python 'sql_server.pyodbc' 不是可用的数据库后端

Mac*_*ack 12 python sql-server django django-pyodbc-azure

我正在尝试将 Django 应用程序连接到 apache 服务器上的 microsoft sql 数据库,但收到以下错误消息:

django.core.exceptions.ImproperlyConfigured: 'sql_server.pyodbc' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3'
Run Code Online (Sandbox Code Playgroud)

我已经安装了 django-pyodbc-azure 并且它显示为(pip freeze list)的一部分:

Django==2.1
django-pyodbc==1.1.3
django-pyodbc-azure==2.1.0.0
pyodbc==4.0.25
Run Code Online (Sandbox Code Playgroud)

这是settings.py数据库配置:

'default': {
    'ENGINE': 'sql_server.pyodbc',
    'NAME': 'name',
    'USER': 'user',
    'PASSWORD': 'password',
    'HOST': 'host',
    'PORT': '',

    'OPTIONS': {
        'driver': 'ODBC Driver 17 for SQL Server',
    },

},
Run Code Online (Sandbox Code Playgroud)

在 site-packages 文件夹内,它不显示实际的 django-pyodbc-azure 文件夹,但是当我运行命令(pip show django-pyodbc-azure)时,它显示包位置(/usr/local/lib/python3.1)。 5/dist-packages)表示安装成功。

所以我不太确定问题是什么。

spr*_*nge 9

我有同样的问题。不知何故,天蓝色后端的安装搞乱了我的项目。

我删除了 django-pyodbc-azure 和 django-mssql-backend 包,因为它们只支持旧的 django 版本。之后我从https://github.com/microsoft/mssql-django安装了 mssql 后端

pip uninstall django-pyodbc-azure
pip uninstall django-mssql-backend
pip install mssql-django
Run Code Online (Sandbox Code Playgroud)

然后我配置了数据库以使用'ENGINE': 'mssql'

此后我能够使用 Django 3.2 和更新版本连接到我们的 MSSQL 数据库!


小智 2

尝试安装pip install django-pyodbc-azure

https://pypi.org/project/django-pyodbc-azure/

我遇到了同样的问题并且使用它有效。

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'Name_database',
        'USER': 'User',
        'PASSWORD': 'Password',
        'HOST': 'IP',
        'PORT': '1433',
        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
        },
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 看来 django-pyodbc-azure 需要 Django 2.*,请注意。 (7认同)