-
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()
-
-
Save aaugustin/9135842 to your computer and use it in GitHub Desktop.
Same problem here when testing a connection. Django 1.11 is not supported
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)]
Required Packages are :
django==1.11.16
django-pyodbc-azure==2.1.0.0
pyodbc=4.0.24
pywin32==224All Above packages are the latest one At the time of posting this post.
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 .
DATABASES = {
'default': {
'NAME': 'abc', #this is your database name
'ENGINE': 'sql_server.pyodbc', #this is your Engine
'HOST': 'x.x.x.x', #MSSQL SERVER ip
'USER': 'user', # username
'PASSWORD': 'password', # password
'OPTIONS': { # mention your Driver Version
'driver': 'ODBC Driver 17 for SQL Server' # Mine Driver version is 2017 so that i mentioned 17 , mention According to yourself
}
}
}
doesn't seem to support django 1.11