问题
Why is it necessary to have both Pyodbc and django-pyodbc-azure installed to interface with recent SQL Server versions with Django? Why can't django just use Pyodbc out of the box? I'm having trouble getting Sql Server to play nice with python 3.4.5, Django 2.1, pyodbc 4.0+, and Django-Pyodbc-azure 2.0.8. I keep getting a segmentation fault thrown when attempting to query certain models that I reflected with inspectdb.
The version of linux that I am using is openSUSE 42.1 The version of Sql Server that I'm using is 2014.
回答1:
django-pyodbc-azure
is the Django engine which translates the Django ORM methods to raw SQL (among other functions). pyodbc
allows Python to run raw SQL queries against the database, through unixODBC
with a driver specific to the database. The same is true for all DB backends; they have both a Django engine and a Python package that work together. With PostgreSQL, for example, it uses the included Django postgresql
engine, which works with the psycopg2
Python package.
Further down the stack for SQL Server, pyodbc
communicates through unixODBC
and either freetds
or the msodbc
Microsoft driver. There are several layers of translation.
The stack, from your web server to your database server for SQL Server:
django-pyodbc-azure
: translates Django's ORM methods to raw SQL.pyodbc
: bridge to unixODBC from PythonunixODBC
library for ODBC communication on *nix.freetds
ormsodbc
: driver bridge from unixODBC to SQL Server.
来源:https://stackoverflow.com/questions/54488316/django-2-0-and-sql-server-interface-question