我是python和djanog的新手。
我使用。安装django。
Pip install django
比我安装了Mssql连接器。
pip install django-mssql
使用此命令运行syncdb。
python manage.py syncdb
它显示所有表都已创建,但我没有在sql server management studio中看到任何表。
之后我尝试使用http:// 127.0.0.1:8000/admin打开Admin panal 它给出了错误。
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'
答案 0 :(得分:1)
对我来说,我用pip安装了django和django-mssql。 django是版本1.6,django-mssql版本是1.4。
来自文档:
当前版本的django-mssql支持Django 1.6。
django-mssql 1.4支持Django 1.4和1.5。
我解决了从源代码安装django-mssql的问题。从bitbucket下载源代码。 https://bitbucket.org/Manfre/django-mssql/get/default.zip或用mercurial克隆它。 然后运行以下命令安装
> python setup.py install
现在检查django-mssql的版本
> python >>> import sqlserver_ado >>> sqlserver_ado.__version__ u'1.5a'
答案 1 :(得分:0)
我不太了解Django,但是,我知道SQL Server。从下面的连接文件:
'default': {
'NAME': 'dbexp',
'ENGINE': 'sqlserver_ado',
'HOST': '172.16.26.51\instance',
'USER': '****',
'PASSWORD': '******',
}
我假设dbexp
是数据库名称,sqlserver_ado
是数据库引擎名称,它也是实例名称。因此,引擎应为sqlserver_ado\instance
,实际主机名为[computer name]/IP(172.16.26.51)
。