8

I wanted to use SQL Server as the backend for Django, but I got this when debugging the web project. 'sql_server.pyodbc' isn't an available database backend. Error was: No module named sql_server.pyodbc.base.

Python Environments (Python 2.7) with Django (1.7), pyodbc(3.0.10), pywin32(218.3). And here is my settings.py:

DATABASES = {
'default': {
    'ENGINE': 'sql_server.pyodbc',
    'NAME': 'DatabaseName',
    'USER': 'user',
    'PASSWORD': 'pwd',
    'HOST': '127.0.0.1',
    'PORT': '',
    'OPTIONS': {
        'driver': 'SQL Server Native Client 11.0',
        'server': 'ServerName',
        'MARS_Connection': True,
        'dsn': 'MSSQL-PYTHON',
        },
    }
}

2 Answers 2

18

You have not installed the package with the required DB backend.

Do:

pip install django-pyodbc
pip install django-pyodbc-azure

See this doc and this one.

An example of the database settings from the second link:

DATABASES = {
'default': {
    'ENGINE': 'sql_server.pyodbc',
    'NAME': 'mydb',
    'USER': 'user@myserver',
    'PASSWORD': 'password',
    'HOST': 'myserver.database.windows.net',
    'PORT': '',

    'OPTIONS': {
        'driver': 'SQL Server Native Client 11.0',
    },
  },
}

#set this to `False` if you want to turn off pyodbc's connection pooling:
DATABASE_CONNECTION_POOLING = False
Sign up to request clarification or add additional context in comments.

6 Comments

I installed django-pyodbc as you suggested, although there is a pyodbc already. It gave me the same error.
It seems still like you haven't got the right backend package. Did you try this one ?
The link you gave about django-pyodbc-azure 1.8.3.0 actually solved the problem. Somehow when I installed it, it also updated my Django to 1.8.4. So I guess matching the version really matters. Please update your answer so I can accept it. Thank you very much!
It seems that django-pyodbc-azure (1.8.3.0) only provides sql_server.pyodbc.base. If I remove pyodbc and leave django-pyodbc-azure alone, it gives me different error. I need both pyodbc (3.0.10) and django-pyodbc-azure (1.8.3.0)
If you don't want to update Django 1.9 to 1.10, do not install the latest version of django-pyodbc-azure. Here are the versions I installed: pyodbc==3.0.10, django-pyodbc==1.0.1, django-pyodbc-azure==1.9.6 ... Cheers!
|
0

Take a look at this link:

DATABASES = {
    'default': {
        'NAME': 'my_database',
        'ENGINE': 'sqlserver_ado',
        'HOST': 'dbserver\\ss2008',
        'USER': '',
        'PASSWORD': '',
    }
}

Supposedly you can use SQL Server with Django MSSQL (link above). you might want to check the [Django documentation] to see what other database support django supports "natively". (https://docs.djangoproject.com/en/1.8/ref/settings/#databases)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.