[英]Django with MSSQL giving error :'DatabaseWrapper' object has no attribute 'Database'
I am newbie to python and djanog. 我是python和djanog的新手。
I install django using. 我安装django使用。
Pip install django
Than I installed Mssql connector. 比我安装了Mssql连接器。
pip install django-mssql
than I run syncdb using this command. 比我使用此命令运行syncdb。
python manage.py syncdb
It shows all tables are created but I didn't see any table in sql server management studio. 它显示所有表都已创建,但是在sql server management studio中没有看到任何表。
After that I tried to open Admin panal using http:// 127.0.0.1:8000/admin it gives error. 之后,我尝试使用http:// 127.0.0.1:8000/admin打开管理员面板,它给出了错误。
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 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'
For me I installed both django and django-mssql with pip. 对我来说,我用pip安装了django和django-mssql。 django was version 1.6 and django-mssql was version 1.4. django是1.6版,django-mssql是1.4版。
From the docs: 从文档:
The current version of django-mssql supports Django 1.6. 当前版本的django-mssql支持Django 1.6。
django-mssql 1.4 supports Django 1.4 and 1.5. django-mssql 1.4支持Django 1.4和1.5。
I solved the problem with installing django-mssql from source. 我从源代码安装django-mssql解决了这个问题。 Download the source from bitbucket. 从bitbucket下载源代码。 https://bitbucket.org/Manfre/django-mssql/get/default.zip or clone it with mercurial. https://bitbucket.org/Manfre/django-mssql/get/default.zip或使用Mercurial克隆它。 Then run the below command to install 然后运行以下命令进行安装
> python setup.py install
Now check the version of django-mssql 现在检查django-mssql的版本
> python >>> import sqlserver_ado >>> sqlserver_ado.__version__ u'1.5a'
I am not much aware of Django, but, I know SQL Server. 我对Django的了解不多,但是我知道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. 我假设dbexp
是数据库名称, sqlserver_ado
是数据库引擎名称,它也是实例名称。 So, the Engine should be sqlserver_ado\\instance
and the actual host name is either the [computer name]/IP(172.16.26.51)
. 因此,引擎应为sqlserver_ado\\instance
,而实际的主机名应为[computer name]/IP(172.16.26.51)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.