Django 2.0+ and SQL Server interface question

≯℡__Kan透↙ 提交于 2019-12-24 11:08:26

问题


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 Python
  • unixODBC library for ODBC communication on *nix.
  • freetds or msodbc: driver bridge from unixODBC to SQL Server.


来源:https://stackoverflow.com/questions/54488316/django-2-0-and-sql-server-interface-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!