Setting up django-mssql issues

笑着哭i 提交于 2019-11-27 15:46:04

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.

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

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/

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'
isaaclw

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!