Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up django-mssql issues

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.

like image 951
rjbez Avatar asked Dec 07 '22 15:12

rjbez


1 Answers

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

like image 112
Seansms Avatar answered Dec 28 '22 20:12

Seansms