在产品中使用Sql Server和Django

时间:2021-10-04 17:33:42

Has anybody got recent experience with deploying a Django application with an SQL Server database back end? Our workplace is heavily invested in SQL Server and will not support Django if there isn't a sufficiently developed back end for it.

有没有人有最近使用SQL Server数据库后部署Django应用程序的经验?我们的workplace在SQL Server上进行了大量的投资,如果没有足够开发的后端,则不会支持Django。

I'm aware of mssql.django-pyodbc and django-mssql as unofficially supported back ends. Both projects seem to have only one person contributing which is a bit of a worry though the contributions seem to be somewhat regular.

我意识到该软件。django-pyodbc和django-mssql作为非官方支持的后端。这两个项目似乎都只有一个人参与,这有点令人担忧,尽管这些贡献似乎是有规律的。

Are there any other back ends for SQL Server that are well supported? Are the two I mentioned here 'good enough' for production? What are your experiences?

SQL Server还有其他支持良好的后端吗?我在这里提到的这两款是否“足够”用于生产?你的经验是什么?

6 个解决方案

#1


20  

As has been stated, django-pyodbc is a good way to go. PyODBC is probably the most mature SQL Server library for Python there is.

如前所述,django-pyodbc是一种很好的方式。PyODBC可能是Python中最成熟的SQL服务器库。

The only thing you may have problems with is that pyodbc doesn't support stored procedures very well (you can call them, but you have no way to get results from them). You can call them using pymssql, but I would avoid it if at all possible as it doesn't support the standard DB-API interface and may be subject to changes. If you need to do this, your best bet is to use adodbapi directly (it's included with the python win32 package, which you'll probably end up installing anyway).

您唯一可能遇到的问题是pyodbc不太支持存储过程(您可以调用它们,但无法从它们获得结果)。您可以使用pymssql调用它们,但是如果可能的话,我将避免使用它,因为它不支持标准的DB-API接口,并且可能会受到更改的影响。如果需要这样做,最好的方法是直接使用adodbapi(它包含在python win32包中,您可能最终会安装它)。

#2


8  

These days

这些天

  • django-mssql: resulted in error "NoneType not callable" upon ./manage.py migrate
  • django-mssql:导致错误“不可调用”。/管理。py迁移
  • avidal/django-pyodbc: unmaintained. Replaced by:
    • django-pyodbc: no support for python 3
    • django-pyodbc:不支持python 3
    • django-pyodbc-azure: works for me so far
      • EDIT: Seems to be unmaintained. Filed issue 125 asking about status
      • 编辑:似乎没有维护。文件第125期询问身份
      • EDIT: got reply from maintainer. Will be made up-to-date with Django 2.0 soon
      • 编辑:得到维护者的回复。Django 2.0会很快更新吗
      • EDIT: maintainer released version 2.0 for django 2.0
      • 编辑:维护者发布了django 2.0版本
    • django-pyodbc-azure:到目前为止,对我来说是可行的。提交第125期关于状态编辑的问题:得到维护者的回复。Django 2.0将会更新吗
  • avidal / django-pyodbc:没有维护。替换为:django-pyodbc:不支持python 3 django-pyodbc-azure:到目前为止对我有效编辑:似乎没有维护。提交第125期关于状态编辑的问题:得到维护者的回复。Django 2.0将会更新吗

EDIT: Here are the package versions

编辑:这是软件包版本

Django==1.11.6
django-mssql==1.8
pyodbc==4.0.19
django-pyodbc==1.1.1
django-pyodbc-azure==1.11.0.0

#3


4  

We are using django-mssql in production at our company. We too had an existing system using mssql. For me personally it was the best design decision I have ever made because my productivity increased dramatically now that I can use django .

我们公司在生产中使用的是django-mssql。我们也有一个使用mssql的现有系统。对我个人来说,这是我所做过的最好的设计决策,因为现在我可以使用django了,我的工作效率大大提高了。

I submitted a patch but when I started using django-mssql and did a week or two of testing.Since then (October 2008) we run our system on django and it runs solid. I also tried pyodbc but I did not like to much.

我提交了一个补丁,但是当我开始使用django-mssql并进行了一两个星期的测试时。从那以后(2008年10月),我们在django上运行我们的系统,它运行稳定。我也尝试了pyodbc,但是我不太喜欢。

We are running a repair system where all transactions run through this system 40 heavy users. If you have more questions let me know.

我们正在运行一个修复系统,在这个系统中,所有的事务都在运行。如果你有更多的问题,请告诉我。

#4


4  

I have seen so many people get the following error after installing django_mssql on Windows:

我见过很多人在Windows上安装django_mssql后出现以下错误:

django.core.exceptions.ImproperlyConfigured: 'sqlserver_ado' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
  'dummy', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named sqlserver_ado.base

The solution is installing the following plugin:

解决方案是安装以下插件:

http://sourceforge.net/projects/pywin32/

http://sourceforge.net/projects/pywin32/

#5


3  

Here's a "modern" answer to this question. I successfully deployed Django 1.11 on a production Ubuntu 16.04 server that connects to MS SQL Server 2017 running on another server.

这个问题有一个“现代”的答案。我成功地在Ubuntu 16.04服务器上部署了Django 1.11,该服务器连接到MS SQL server 2017运行在另一台服务器上。

First, install the native MS ODBC driver "ODBC Driver 17 for SQL Server":

首先,安装本地MS ODBC驱动程序“SQL Server的ODBC驱动程序17”:

# https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server#ubuntu-1404-1604-and-1710
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install msodbcsql
apt-get install unixodbc-dev

# test you can actually get to port 1433 on the server that is running MS SQL:
nc -z -v -w5 host.where.sql.server.is.running.com 1433

# add /opt/mssql-tools/bin to your PATH in .bash_profile, e.g.:
# PATH="$HOME/bin:$HOME/.local/bin:/opt/mssql-tools/bin:$PATH"
# source ~/.bash_profile
# now, test that you can actually connect to MS SQL Server:
sqlcmd -S host.where.sql.server.is.running.com -U db_username -P db_password

Second, make sure you pip install these modules:

第二,确保您pip安装这些模块:

# https://github.com/michiya/django-pyodbc-azure
django-pyodbc-azure==1.11.9.0

# https://github.com/mkleehammer/pyodbc/wiki
pyodbc==4.0.22

Third, modify the DATABASES entry of your Django settings.py:

第三,修改Django设置的数据库条目。

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'db_name',
        'USER': 'db_username',
        'PASSWORD': 'db_password',
        'HOST': 'host.where.sql.server.is.running.com',
        'PORT': '1433',
        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
        },
    },
}

I'm omitting the rest of my configuration (nginx, Gunicorn, Django REST Framework, etc), but that's outside the scope of this answer.

我省略了其余的配置(nginx、Gunicorn、Django rest框架等),但这超出了这个答案的范围。

#6


1  

Haven't used it in production yet, but my initial experiences with django-mssql have been pretty solid. All you need are the Python Win32 extensions and to get the sqlserver_ado module onto your Python path. From there, you just use sql_server.pyodbc as your DATABASE_ENGINE. So far I haven't noticed anything missing, but I haven't fully banged on it yet either.

还没有在生产中使用它,但是我在django-mssql的最初经验是相当可靠的。您所需要的只是Python Win32扩展和将sqlserver_ado模块放到Python路径上。从这里开始,您只需使用sql_server。pyodbc DATABASE_ENGINE。到目前为止,我还没有注意到有什么遗漏,但我也还没有完全注意到。

#1


20  

As has been stated, django-pyodbc is a good way to go. PyODBC is probably the most mature SQL Server library for Python there is.

如前所述,django-pyodbc是一种很好的方式。PyODBC可能是Python中最成熟的SQL服务器库。

The only thing you may have problems with is that pyodbc doesn't support stored procedures very well (you can call them, but you have no way to get results from them). You can call them using pymssql, but I would avoid it if at all possible as it doesn't support the standard DB-API interface and may be subject to changes. If you need to do this, your best bet is to use adodbapi directly (it's included with the python win32 package, which you'll probably end up installing anyway).

您唯一可能遇到的问题是pyodbc不太支持存储过程(您可以调用它们,但无法从它们获得结果)。您可以使用pymssql调用它们,但是如果可能的话,我将避免使用它,因为它不支持标准的DB-API接口,并且可能会受到更改的影响。如果需要这样做,最好的方法是直接使用adodbapi(它包含在python win32包中,您可能最终会安装它)。

#2


8  

These days

这些天

  • django-mssql: resulted in error "NoneType not callable" upon ./manage.py migrate
  • django-mssql:导致错误“不可调用”。/管理。py迁移
  • avidal/django-pyodbc: unmaintained. Replaced by:
    • django-pyodbc: no support for python 3
    • django-pyodbc:不支持python 3
    • django-pyodbc-azure: works for me so far
      • EDIT: Seems to be unmaintained. Filed issue 125 asking about status
      • 编辑:似乎没有维护。文件第125期询问身份
      • EDIT: got reply from maintainer. Will be made up-to-date with Django 2.0 soon
      • 编辑:得到维护者的回复。Django 2.0会很快更新吗
      • EDIT: maintainer released version 2.0 for django 2.0
      • 编辑:维护者发布了django 2.0版本
    • django-pyodbc-azure:到目前为止,对我来说是可行的。提交第125期关于状态编辑的问题:得到维护者的回复。Django 2.0将会更新吗
  • avidal / django-pyodbc:没有维护。替换为:django-pyodbc:不支持python 3 django-pyodbc-azure:到目前为止对我有效编辑:似乎没有维护。提交第125期关于状态编辑的问题:得到维护者的回复。Django 2.0将会更新吗

EDIT: Here are the package versions

编辑:这是软件包版本

Django==1.11.6
django-mssql==1.8
pyodbc==4.0.19
django-pyodbc==1.1.1
django-pyodbc-azure==1.11.0.0

#3


4  

We are using django-mssql in production at our company. We too had an existing system using mssql. For me personally it was the best design decision I have ever made because my productivity increased dramatically now that I can use django .

我们公司在生产中使用的是django-mssql。我们也有一个使用mssql的现有系统。对我个人来说,这是我所做过的最好的设计决策,因为现在我可以使用django了,我的工作效率大大提高了。

I submitted a patch but when I started using django-mssql and did a week or two of testing.Since then (October 2008) we run our system on django and it runs solid. I also tried pyodbc but I did not like to much.

我提交了一个补丁,但是当我开始使用django-mssql并进行了一两个星期的测试时。从那以后(2008年10月),我们在django上运行我们的系统,它运行稳定。我也尝试了pyodbc,但是我不太喜欢。

We are running a repair system where all transactions run through this system 40 heavy users. If you have more questions let me know.

我们正在运行一个修复系统,在这个系统中,所有的事务都在运行。如果你有更多的问题,请告诉我。

#4


4  

I have seen so many people get the following error after installing django_mssql on Windows:

我见过很多人在Windows上安装django_mssql后出现以下错误:

django.core.exceptions.ImproperlyConfigured: 'sqlserver_ado' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
  'dummy', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named sqlserver_ado.base

The solution is installing the following plugin:

解决方案是安装以下插件:

http://sourceforge.net/projects/pywin32/

http://sourceforge.net/projects/pywin32/

#5


3  

Here's a "modern" answer to this question. I successfully deployed Django 1.11 on a production Ubuntu 16.04 server that connects to MS SQL Server 2017 running on another server.

这个问题有一个“现代”的答案。我成功地在Ubuntu 16.04服务器上部署了Django 1.11,该服务器连接到MS SQL server 2017运行在另一台服务器上。

First, install the native MS ODBC driver "ODBC Driver 17 for SQL Server":

首先,安装本地MS ODBC驱动程序“SQL Server的ODBC驱动程序17”:

# https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server#ubuntu-1404-1604-and-1710
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install msodbcsql
apt-get install unixodbc-dev

# test you can actually get to port 1433 on the server that is running MS SQL:
nc -z -v -w5 host.where.sql.server.is.running.com 1433

# add /opt/mssql-tools/bin to your PATH in .bash_profile, e.g.:
# PATH="$HOME/bin:$HOME/.local/bin:/opt/mssql-tools/bin:$PATH"
# source ~/.bash_profile
# now, test that you can actually connect to MS SQL Server:
sqlcmd -S host.where.sql.server.is.running.com -U db_username -P db_password

Second, make sure you pip install these modules:

第二,确保您pip安装这些模块:

# https://github.com/michiya/django-pyodbc-azure
django-pyodbc-azure==1.11.9.0

# https://github.com/mkleehammer/pyodbc/wiki
pyodbc==4.0.22

Third, modify the DATABASES entry of your Django settings.py:

第三,修改Django设置的数据库条目。

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'db_name',
        'USER': 'db_username',
        'PASSWORD': 'db_password',
        'HOST': 'host.where.sql.server.is.running.com',
        'PORT': '1433',
        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
        },
    },
}

I'm omitting the rest of my configuration (nginx, Gunicorn, Django REST Framework, etc), but that's outside the scope of this answer.

我省略了其余的配置(nginx、Gunicorn、Django rest框架等),但这超出了这个答案的范围。

#6


1  

Haven't used it in production yet, but my initial experiences with django-mssql have been pretty solid. All you need are the Python Win32 extensions and to get the sqlserver_ado module onto your Python path. From there, you just use sql_server.pyodbc as your DATABASE_ENGINE. So far I haven't noticed anything missing, but I haven't fully banged on it yet either.

还没有在生产中使用它,但是我在django-mssql的最初经验是相当可靠的。您所需要的只是Python Win32扩展和将sqlserver_ado模块放到Python路径上。从这里开始,您只需使用sql_server。pyodbc DATABASE_ENGINE。到目前为止,我还没有注意到有什么遗漏,但我也还没有完全注意到。