1

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.

Jasonca1
  • 4,848
  • 6
  • 25
  • 42
  • I think it would better to add information: a) python and django version, b) OS, c) SQLServer version, d) database section of settings.py, e) how did you tested connectivity – Alex Yu Feb 01 '19 at 23:24
  • Please clarify: a) you need to solve actual problem in practice or b) you're asking purely theoretical question? – Alex Yu Feb 01 '19 at 23:26
  • @AlexYu I need to solve a problem (I'm thinking of just using a docker container instead as I'm tired of wasting time trying to figure it out). Basically I am limited to the system install of python 3.4.5 on our server. I am only able to install Django 2.1.0 from this, and to interface with SQL Server I have to have (in addition to Pyodbc), django-pyodbc-azure installed as well (however I can only install 2.0.8 with Django 2.1.0). On my local machine running python 3.5 I was able to install django 2.1+ and the latest version of django-pyodbc-azure and all works fine. – Jasonca1 Feb 02 '19 at 00:05
  • On the server I keep getting a seg fault when attempting to query certain models that query just fine on my local machine running python 3.5 and the latest version of django-pyodbc-azure. – Jasonca1 Feb 02 '19 at 00:05
  • 1
    Add this this to your question **and**: a) it's still unknown which OS you use. MSSQL 2016 works on linux just fine b) how do you get segfault? Show `cmd`/`pwsh`/`sh` command you use c) 'settings.py' d) in case you use `pip/`pipenv` - show your Pipfile/requirement.txt. Help community to help you: don't make us **suppose** things, write them down – Alex Yu Feb 02 '19 at 00:44
  • @Jasonca1 You need to match the version of `django-pyodbc-azure` to the version of Django you're running. Match the highest version of `django-pyodbc-azure` that is equal to or lower your version of Django: https://pypi.org/project/django-pyodbc-azure/#history Since you're running Django 2.1, try `pip install django-pyodbc-azure==2.1.0.0` – FlipperPA Feb 03 '19 at 03:01
  • @FlipperPA I have django-pyodbc-azure 2.0.8 installed which coincides with Django 2.0.8, which I also have installed. I am still getting a segmentation fault when attempting to query a model that queries fine on my local machine with python 3.5 installed. My version of pyodbc is above 4.0, but django-pyodbc-azure only needs 3.0+. Should I downgrade my version of pyodbc? – Jasonca1 Feb 06 '19 at 21:40

1 Answers1

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.
FlipperPA
  • 13,607
  • 4
  • 39
  • 71