gpt4 book ai didi

python - 带有 MSSQL 的 Django 给出错误 :'DatabaseWrapper' 对象没有属性 'Database'

转载 作者:太空宇宙 更新时间:2023-11-03 18:36:46 28 4
gpt4 key购买 nike

我是 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 打开管理面板它给出了错误。

错误

'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

设置.PY

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

堆栈跟踪

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'

最佳答案

对我来说,我使用 pip 安装了 django 和 django-mssql。 django 是版本 1.6,django-mssql 是版本 1.4。

来自文档:

The current version of django-mssql supports Django 1.6.

django-mssql 1.4 supports Django 1.4 and 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'

关于python - 带有 MSSQL 的 Django 给出错误 :'DatabaseWrapper' 对象没有属性 'Database',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21429975/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com