Ritesh Chandora
Ritesh Chandora

Reputation: 8640

Django with MSSQL giving error :'DatabaseWrapper' object has no attribute 'Database'

I am newbie to python and djanog.

I install django using.

Pip install django

Than I installed Mssql connector.

pip install django-mssql

than I run syncdb using this command.

python manage.py syncdb

It shows all tables are created but I didn't see any table in sql server management studio.

After that I tried to open Admin panal using http:// 127.0.0.1:8000/admin it gives error.

ERROR

'DatabaseWrapper' object has no attribute 'Database'
Following is error:    
Request Method: GET    
Request URL:    http:// 127.0.0.1:8000/admin    
Django Version: 1.6.1    
Exception Type: AttributeError    
Exception Value: 'DatabaseWrapper' object has no attribute 'Database'     
Exception Location: C:\Python27\lib\site-packages\django\db\utils.py in __exit__, line 86
Python Executable:  C:\Python27\python.exe
Python Version: 2.7.6

SETTING.PY

DATABASES = {
 'default': {
    'NAME': 'dbexp',
    'ENGINE': 'sqlserver_ado',
    'HOST': '172.16.26.51\instance',
    'USER': '****',
    'PASSWORD': '******',
 }
}

STACK TRACE

Environment:
Request Method: GET
Request URL: http: //127.0.0.1:8000/admin/

Django Version: 1.6.1
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py" in wrapper
  215.                 return self.admin_view(view, cacheable)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py" in inner
  192.             if not self.has_permission(request):
File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py" in has_permission
  143.         return request.user.is_active and request.user.is_staff
File "C:\Python27\lib\site-packages\django\utils\functional.py" in inner
  213.             self._setup()
File "C:\Python27\lib\site-packages\django\utils\functional.py" in _setup
  298.         self._wrapped = self._setupfunc()
File "C:\Python27\lib\site-packages\django\contrib\auth\middleware.py" in <lambda>
  18.         request.user = SimpleLazyObject(lambda: get_user(request))
File "C:\Python27\lib\site-packages\django\contrib\auth\middleware.py" in get_user
  10.         request._cached_user = auth.get_user(request)
File "C:\Python27\lib\site-packages\django\contrib\auth\__init__.py" in get_user
  140.         user_id = request.session[SESSION_KEY]
File "C:\Python27\lib\site-packages\django\contrib\sessions\backends\base.py" in __getitem__
  47.         return self._session[key]
File "C:\Python27\lib\site-packages\django\contrib\sessions\backends\base.py" in _get_session
  173.                 self._session_cache = self.load()
File "C:\Python27\lib\site-packages\django\contrib\sessions\backends\db.py" in load
  20.                 expire_date__gt=timezone.now()
File "C:\Python27\lib\site-packages\django\db\models\manager.py" in get
  151.         return self.get_queryset().get(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in get
  301.         num = len(clone)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in __len__
  77.         self._fetch_all()
File "C:\Python27\lib\site-packages\django\db\models\query.py" in _fetch_all
  854.             self._result_cache = list(self.iterator())
File "C:\Python27\lib\site-packages\django\db\models\query.py" in iterator
  220.         for row in compiler.results_iter():
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py" in results_iter
  710.         for rows in self.execute_sql(MULTI):
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
  781.         cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\util.py" in execute
  69.             return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\util.py" in execute
  53.                 return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\utils.py" in __exit__
  86.             db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__)

Exception Type: AttributeError at /admin/
Exception Value: 'DatabaseWrapper' object has no attribute 'Database'

Upvotes: 1

Views: 3861

Answers (2)

user3139842of9
user3139842of9

Reputation: 46

For me I installed both django and django-mssql with pip. django was version 1.6 and django-mssql was version 1.4.

From the docs:

The current version of django-mssql supports Django 1.6.

django-mssql 1.4 supports Django 1.4 and 1.5.

I solved the problem with installing django-mssql from source. Download the source from bitbucket. https://bitbucket.org/Manfre/django-mssql/get/default.zip or clone it with mercurial. Then run the below command to install

> python setup.py install

Now check the version of django-mssql

> python
>>> import sqlserver_ado
>>> sqlserver_ado.__version__
u'1.5a'

Upvotes: 1

Adarsh
Adarsh

Reputation: 52

I am not much aware of Django, but, I know SQL Server. From the connection file below:

'default': {
'NAME': 'dbexp',
'ENGINE': 'sqlserver_ado',
'HOST': '172.16.26.51\instance',
'USER': '****',
'PASSWORD': '******',
}

I assume dbexp is the database name, sqlserver_ado is the database Engine name, which is also the Instance name. So, the Engine should be sqlserver_ado\instance and the actual host name is either the [computer name]/IP(172.16.26.51).

Upvotes: 0

Related Questions