-
Install and register the FreeTDS driver for unixODBC.
apt-get install tdsodbc odbcinst -i -d -f /usr/share/tdsodbc/odbcinst.ini
-
(Optional) Test the DSN-less connection with pyodbc.
apt-get install python-pyodbc >>> import pyodbc >>> pyodbc.connect("DRIVER=FreeTDS;SERVER=...;PORT=1433;UID=...;PWD=...;DATABASE=...") <pyodbc.Connection object at ...> apt-get remove python-pyodbc
-
In your project's virtualenv, install django-pyodbc.
apt-get install python-dev unixodbc-dev # If you have an old version of pip: pip install django-pyodbc # If you have a recent version of pip: pip install --allow-external pyodbc --all-unverified pyodbc django-pyodbc
-
Edit the DATABASES setting in your Django project.
DATABASES = { '...': { 'ENGINE': 'django_pyodbc', 'NAME': '...', 'HOST': '...', 'PORT': 1433, 'USER': '...', 'PASSWORD': '...', 'OPTIONS': { 'host_is_server': True, } } }
-
Test the connection in
./manage.py shell
.>>> from django.db import connection >>> cursor = connection.cursor() >>> cursor.execute("SELECT 2 + 2") <pyodbc.Cursor object at ...> >>> cursor.fetchall() [(4,)] >>> cursor.close()
Last active
December 3, 2019 20:18
-
-
Save aaugustin/9135842 to your computer and use it in GitHub Desktop.
Connecting a Django application to a Microsoft SQL Server database from Debian GNU/Linux
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After Lost of Searching in django docs and i think most of the link in Google regarding Django with MSSQL Server below are my Configurations.
My python version is
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]
For Downloading pywin32 use this link (Latest version is 224)
https://github.com/mhammond/pywin32/releases
After that you need to download SQL SERVER driver, i am currently on windows 10 so i downloaded the latest one that 2017 SQL SERVER DRIVER.
https://www.microsoft.com/en-us/download/details.aspx?id=56567
After that in Django Settings.py file this is my Configuration
if you did not mention your driver version in option field this will not work so be attentive .