3
votes

I have got following in my django env

Django==1.8.1
django-mssql==1.6.2
django-pyodbc==0.2.8
pyodbc==3.0.10
pywin32==219 
sql-server.pyodbc==1.0

and the following in my settings.py

DATABASES = {
  'default': {
    'NAME': 'db_name',
    'ENGINE': 'sqlserver_ado',
    'HOST': 'host_name\\SQLEXPRESS',
    'USER': 'user_name',
    'PASSWORD': 'password',
  }
}

But when I try to migrate it I face the following error. Am I missing out something?

django.core.exceptions.ImproperlyConfigured: 'sqlserver_ado' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'base', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: cannot import name 'BaseDatabaseWrapper'
7
See this answer. - doru
I am using sql server 2012 but there they mention as 2005/2008. Though I tried it. I get the same error. I have the complete sqlserver_ado folder in /site-packages/ - Kiran Kumar
looks like you have an extra comma after password fwiw - Hack-R

7 Answers

1
votes

I had been using django 1.8, and solved it by downgrading to django 1.6. These are the libraries installed in my virtualenv after the downgrade, and when I got it working.:

(env)$ pip list
argparse (1.2.1)                                         
Django (1.6)                                             
django-pyodbc (0.2.8)                                    
pip (1.5.4)                                              
pyodbc (3.0.10)                                          
setuptools (2.2)                                         
wsgiref (0.1.2)                                          
1
votes

You need to install the python package django-sqlserver.

1
votes

Try using django-pyodbc instead.

In settings.py, replace the ENGINE setting with this:

'ENGINE': 'django_pyodbc',
1
votes

Try these settings with Django version 1.8.

DATABASES = {
'default': {
    'ENGINE': 'sqlserver_ado',
    'NAME': '',
    'USER': '',
    'PASSWORD': '',
    'HOST': '',
    'PORT': '1433',
     'OPTIONS': {
        'provider': 'SQLOLEDB', #SQLNCLI11 , SQLOLEDB
        'use_legacy_date_fields': 'True',
        #'extra_params' : 'DataTypeCompatibility=80;MARS Connection=True',
        #'connect_timeout': 0
        }
}

}

0
votes

For Django Version 1.11 I am using this settings:

DATABASES = {
   'default': {
       'NAME': 'DbName',
       'ENGINE': 'sql_server.pyodbc',
       'HOST': 'localhost',
       'PORT': '1433',
       'USER': 'DBUser',
       'PASSWORD': 'Db password',
       'OPTIONS': {
                    'driver': 'ODBC Driver 13 for SQL Server'
                  }
    }
}
0
votes

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==224

All 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 
        }
    }
}
0
votes

If u add an option like :

'OPTIONS': {
                    'driver': 'ODBC Driver 13 for SQL Server'
                  }

U have to make sure u already install OCBC Driver 13 for SQL Server. (This would be inside Administrative Tools> Data Source OCBC and when u click Add button this driver should be in the list otherwise u have to install)

If still not working, try to install: pip install django-pyodbc-azure