4

I'm having some issues setting up django-mssql on Win Server 2008 R2. I have everything installed, however, the wiki for django-mssql says to setup the settings file similar to:

DATABASES = {
'default': {
 'NAME': 'my_database',
 'ENGINE': 'sqlserver_ado',
 'HOST': 'dbserver\\ss2008',
 'USER': '',
 'PASSWORD': '',
 'OPTIONS' : {
 'provider': 'SQLOLEDB',
 'use_mars': True,
 },
 }
}

When I run from my site directory:

 python manage.py syncdb

I get an error stating it isn't an available database backend. When I installed django-mssql it seemed to install the backend here \site-packages\django_mssql-1.0.1-py2.7.egg\sqlserver_ado does this need to be copied to site-packages\django\db\backends?

I get the same error if I set my settings to:

DATABASES = {
'default': {
 'NAME': 'my_database',
 'ENGINE': 'django_mssql-1.0.1-py2.7.egg.sqlserver_ado',
 'HOST': 'dbserver\\ss2008',
 'USER': '',
 'PASSWORD': '',
 'OPTIONS' : {
 'provider': 'SQLOLEDB',
 'use_mars': True,
 },
 }
}

Am I missing something when setting up this backend? This is my first time using django, but I didn't see anything in the documentation for setting up a different backend, and the django-mssql wiki or issues doesn't seem to have anything either.

Also, if there is other documentation somewhere that can help please let me know.

EDIT: The django app is running on Ubuntu server.

asked Mar 30, 2012 at 13:44
3
  • I would not copy external files into your Django directory. Not a good idea. But you probaly need to import the backend somewhere in your settings files. Maybe try from mssql import *? Commented Mar 30, 2012 at 16:25
  • When you decide to upgrade to Django 1.4, you'll need to update to django-mssql v1.1. pip install django-mssql==1.1 Commented Jun 13, 2012 at 20:24
  • Thanks, glad they updated it to work with 1.4 Commented Jun 14, 2012 at 16:02

6 Answers 6

6

Dustin's comment about making sure "import sqlserver_ado" from the command shell got me going down the right path on my Django 1.8.1, Python 3.5 Win32 system with pywin32 installed.

SPOILER ALERT This only gets my Django instance to run without errors. I haven't tested the ADO connection yet.

The first error message I got was:

No module named 'django.db.backends.util'

and I found there is a file called: django.db.backends.utils so I copied it and renamed it to django.db.backends.util (without the 's') and away went the error message!

So hoping this wasn't too harmful, I continued on this line of troubleshooting.

The next error message I got was:

 File "C:\Program Files (x86)\Python35-32\lib\site-packages\sqlserver_ado\base.py", line 7, in <module>
from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseValidation, BaseDatabaseClient 
ImportError: cannot import name 'BaseDatabaseWrapper'

I changed line 7 in base.py to now say:

#from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseValidation, BaseDatabaseClient
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.base.features import BaseDatabaseFeatures
from django.db.backends.base.validation import BaseDatabaseValidation
from django.db.backends.base.client import BaseDatabaseClient

Yes, that's commenting out the bad line and adding four separate lines. Then I got this error:

 File "C:\Program Files (x86)\Python35-32\lib\site-packages\sqlserver_ado\base.py", line 18, in <module>
from .introspection import DatabaseIntrospection

File "C:\Program Files (x86)\Python35-32\lib\site-packages\sqlserver_ado\introspection.py", line 3, in from django.db.backends import BaseDatabaseIntrospection ImportError: cannot import name 'BaseDatabaseIntrospection'

so I changed the line 3 to now read:

from django.db.backends.base.introspection import BaseDatabaseIntrospection

and so on for creation.py:

from django.db.backends.base.creation import BaseDatabaseCreation

for operations.py:

from django.db.backends.base.operations import BaseDatabaseOperations

for schema.py:

from django.utils.log import getLogger

Hope this helps someone. Hope the ADO module actually connects to something.

-Sean

answered May 2, 2016 at 7:56
Sign up to request clarification or add additional context in comments.

2 Comments

Just had this exact same issue. Fresh install of django, pywin32 and django-mssql and I've fell at the first hurdle.Is this a bug? I am using python 2.7
from logging import getLogger did the job on the last part
5

You will want to make sure that you can import "sqlserver_ado" from your python shell.

Put the folder sqlserver_ado somewhere on your PATH, I put mine in \site-packages\

Take a look at the README.txt.

The engine does want to be set to "sqlserver_ado" similar to how the settings are done on the settings sample page.

answered Apr 13, 2012 at 0:49

2 Comments

This seemed to do it...the documentation I had didn't have that tid-bit. Thanks.
One other thing for to consider is update to pywin32. See stackoverflow.com/questions/4145079/…
3

As of 2019:

I couldn't get Django MSSQL to work at all.

I switched over to django-pyodbc-azure and that works great.

Install:

pip install django-pyodbc-azure

Setup:

'ENGINE': 'sql_server.pyodbc'
answered Jan 18, 2019 at 22:08

2 Comments

This uses djang<=2.1
I was running Django 3.1.7 and installing django-pyodbc-azure caused it downgrade to Django 2.1.15 which made other code break. I had to "pip install Django=3.1.7" to recover.
1

You need to install the dependency PyWin32. You can install via pip or download from the python binaries page http://www.lfd.uci.edu/~gohlke/pythonlibs/

answered Mar 3, 2014 at 15:24

1 Comment

Sorry, this wasn't mentioned above but the django app is running on Ubuntu. So the PyWin32 wont install.
1

I was trying to get django_pyodbc to work, and couldn't. I was getting this error:

django.core.exceptions.ImproperlyConfigured: 'django_pyodbc' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
 u'base', u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: cannot import name BaseDatabaseWrapper

I was directed to this post as a solution, so I'll post my answer here also. I downgraded to django 1.6 instead of 1.8, and now django_pyodbc works as a database backend.

answered May 12, 2015 at 3:09

Comments

0

As per https://github.com/lionheart/django-pyodbc/pull/96, django_pyodbc should now work with Django 1.8. So this seems to be a good alternative to django-mssql for those requiring SQL Server 2008 R2 support.

answered Jan 13, 2016 at 19:05

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.