简体   繁体   English

AttributeError:“ DatabaseWrapper”对象没有属性“ Database”

[英]AttributeError: 'DatabaseWrapper' object has no attribute 'Database'

Version numbers are Django 1.6, Python 3.3.2 and Mac OS X 10.9 版本号是Django 1.6,Python 3.3.2和Mac OS X 10.9

I create an app with this command 我用此命令创建一个应用

 python3 manage.py startapp lists

Then in my lists/tests.py file I put this code 然后在我的lists / tests.py文件中输入以下代码

from django.test import TestCase

class SmokeTest(TestCase):

 def test_bad_maths(self):
    self.assertEqual(1 + 1, 3)

then I run this command from the app root folder 然后我从应用程序根文件夹运行此命令

python3 manage.py test

and this is the stack trace that comes back, it's not working correctly 这是返回的堆栈跟踪,它无法正常工作

    E

         ======================================================================
ERROR: test_bad_maths (lists.tests.SmokeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 111, in connect
    conn_params = self.get_connection_params()
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 85, in get_connection_params
    raise NotImplementedError
NotImplementedError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 653, in supports_transactions
    self.connection.enter_transaction_management()
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 288, in enter_transaction_management
    if managed == self.get_autocommit():
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 324, in get_autocommit
    self.ensure_connection()
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.3/site-packages/django/db/utils.py", line 86, in __exit__
    db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__)
AttributeError: 'DatabaseWrapper' object has no attribute 'Database'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 111, in connect
    conn_params = self.get_connection_params()
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 85, in get_connection_params
    raise NotImplementedError
NotImplementedError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 178, in __call__
    self._pre_setup()
  File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 749, in _pre_setup
    self._fixture_setup()
  File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 861, in _fixture_setup
    if not connections_support_transactions():
  File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 848, in connections_support_transactions
    for conn in connections.all())
  File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 848, in <genexpr>
    for conn in connections.all())
  File "/usr/local/lib/python3.3/site-packages/django/utils/functional.py", line 49, in __get__
    res = instance.__dict__[self.func.__name__] = self.func(instance)
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 664, in supports_transactions
    self.connection.leave_transaction_management()
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 317, in leave_transaction_management
    if managed == self.get_autocommit():
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 324, in get_autocommit
    self.ensure_connection()
  File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.3/site-packages/django/db/utils.py", line 86, in __exit__
    db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__)
AttributeError: 'DatabaseWrapper' object has no attribute 'Database'

----------------------------------------------------------------------
Ran 0 tests in 0.031s

FAILED (errors=1)

I have exact the same environment: * Mac OS X 10.9 * Python 3.3.2 * Django 1.6 我有完全相同的环境:* Mac OS X 10.9 * Python 3.3.2 * Django 1.6

I have virtualenv 1.10.1 installed and create one, install django and create the project and app: 我安装了virtualenv 1.10.1并创建了一个,安装了django并创建了项目和应用程序:

virtualenv-3.3 tt
cd tt
. bin/activate
pip install django==1.6
django-admin.py startproject myproj
cd myproj
chmod +x manage.py
./manage.py startapp lists

Now I pasted your code into lists/test.py and run the test with the default settings.py (database sqlite3, etc.) 现在,我将您的代码粘贴到list / test.py中,并使用默认settings.py(数据库sqlite3等)运行测试。

./manage.py test

and got the right results: 并得到正确的结果:

Creating test database for alias 'default'... 正在为别名“默认”创建测试数据库...

F
======================================================================
FAIL: test_bad_maths (lists.tests.SmokeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/erevilla/tt/myproj/lists/tests.py", line 6, in test_bad_maths
    self.assertEqual(1 + 1, 3)
AssertionError: 2 != 3

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (failures=1)
Destroying test database for alias 'default'...

I can't reproduce your problem. 我无法重现您的问题。 Please check: 请检查:

  • settings.py (what database are you using) settings.py(您正在使用哪个数据库)
  • manage.py (for incorrect version) manage.py(用于错误的版本)
  • DJANGO_SETTINGS_MODULE is undefined DJANGO_SETTINGS_MODULE未定义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 异常值:“ DatabaseWrapper”对象没有属性“ Database” - Exception Value: 'DatabaseWrapper' object has no attribute 'Database' 使用标准Unittest测试Django:“ DatabaseWrapper”对象没有属性“ Database” - testing Django with standard Unittest: 'DatabaseWrapper' object has no attribute 'Database' 带有MSSQL的Django提供错误:“ DatabaseWrapper”对象没有属性“ Database” - Django with MSSQL giving error :'DatabaseWrapper' object has no attribute 'Database' django+mysql=&#39;DatabaseWrapper&#39; 对象没有属性 &#39;Database&#39; 错误 - django+mysql='DatabaseWrapper' object has no attribute 'Database' error Django简单验证码-{{form.as_p}}中的错误-&#39;DatabaseWrapper&#39;对象没有属性&#39;Database&#39; - Django Simple Captcha - Error in {{ form.as_p }} - 'DatabaseWrapper' object has no attribute 'Database' AttributeError: 类型对象“数据库”没有属性“scoreDB” - AttributeError: type object 'Database' has no attribute 'scoreDB' AttributeError: 'AnimalShelter' object 没有属性 'database' - AttributeError: 'AnimalShelter' object has no attribute 'database' AttributeError:类型 object 'database' 没有属性 'initialize' - AttributeError: type object 'database' has no attribute 'initialize' AttributeError: 'AttributeError' object 没有属性 'To' - AttributeError: 'AttributeError' object has no attribute 'To' AttributeError:对象没有属性 - AttributeError: object has no attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM