ProgrammingError:运行django测试时,关系“django_redirect”不存在

时间:2015-02-11 15:59:37

标签: python django unit-testing django-south

我正在尝试使用django进行一个非常简单的测试:

类PaymentTests(TestCase):

    def setUp(self):
        self.c = Client()

    def test_can_see_chat_for_an_anynomous_user(self):
        response = self.c.get('/')
        self.assertEqual(200, response.status_code)

不幸的是每次我尝试运行它都会出错:

(project)linoor@linoor-virtual-machine /mnt/hgfs/Dev/LegalStart/project $ python manage.py test --rednose useracts.tests:PaymentTests
nosetests useracts.tests:PaymentTests --rednose --verbosity=1
Creating test database for alias 'default'...
ERROR 2015-02-11 16:37:00,082 Internal Server Error: /
Traceback (most recent call last):
  File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 105, in get_response
    response = middleware_method(request, callback, callback_args, callback_kwargs)
  File "/mnt/hgfs/Dev/LegalStart/project/staticpages/middleware.py", line 56, in process_view
    r = Redirect.objects.get(old_path='/' + slug)
  File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/manager.py", line 151, in get
    return self.get_queryset().get(*args, **kwargs)
  File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/query.py", line 304, in get
    num = len(clone)
  File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/query.py", line 77, in __len__
    self._fetch_all()
  File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/query.py", line 857, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
    for row in compiler.results_iter():
  File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 713, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
    cursor.execute(sql, params)
  File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)
ProgrammingError: relation "django_redirect" does not exist
LINE 1: ...ct"."old_path", "django_redirect"."new_path" FROM "django_re...
                                                             ^

X
-----------------------------------------------------------------------------
1) ERROR: test_can_see_chat_for_an_anynomous_user (useracts.tests.PaymentTests)

   Traceback (most recent call last):
    useracts/tests.py line 48 in test_can_see_chat_for_an_anynomous_user
      response = self.c.post('/')
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/test/client.py line 483 in post
      response = super(Client, self).post(path, data=data, content_type=content_type, **extra)
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/test/client.py line 302 in post
      return self.request(**r)
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/test/client.py line 444 in request
      six.reraise(*exc_info)
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/core/handlers/base.py line 105 in get_response
      response = middleware_method(request, callback, callback_args, callback_kwargs)
    staticpages/middleware.py line 56 in process_view
      r = Redirect.objects.get(old_path='/' + slug)
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/manager.py line 151 in get
      return self.get_queryset().get(*args, **kwargs)
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/query.py line 304 in get
      num = len(clone)
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/query.py line 77 in __len__
      self._fetch_all()
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/query.py line 857 in _fetch_all
      self._result_cache = list(self.iterator())
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/query.py line 220 in iterator
      for row in compiler.results_iter():
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py line 713 in results_iter
      for rows in self.execute_sql(MULTI):
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py line 786 in execute_sql
      cursor.execute(sql, params)
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/backends/util.py line 53 in execute
      return self.cursor.execute(sql, params)
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/utils.py line 99 in __exit__
      six.reraise(dj_exc_type, dj_exc_value, traceback)
    /home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/backends/util.py line 53 in execute
      return self.cursor.execute(sql, params)
   ProgrammingError: relation "django_redirect" does not exist
   LINE 1: ...ct"."old_path", "django_redirect"."new_path" FROM "django_re...
                                                                ^

   -------------------- >> begin captured logging << --------------------
   django.request: ERROR: Internal Server Error: /
   Traceback (most recent call last):
     File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 105, in get_response
       response = middleware_method(request, callback, callback_args, callback_kwargs)
     File "/mnt/hgfs/Dev/LegalStart/project/staticpages/middleware.py", line 56, in process_view
       r = Redirect.objects.get(old_path='/' + slug)
     File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/manager.py", line 151, in get
       return self.get_queryset().get(*args, **kwargs)
     File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/query.py", line 304, in get
       num = len(clone)
     File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/query.py", line 77, in __len__
       self._fetch_all()
     File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/query.py", line 857, in _fetch_all
       self._result_cache = list(self.iterator())
     File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
       for row in compiler.results_iter():
     File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 713, in results_iter
       for rows in self.execute_sql(MULTI):
     File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
       cursor.execute(sql, params)
     File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
       return self.cursor.execute(sql, params)
     File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
       six.reraise(dj_exc_type, dj_exc_value, traceback)
     File "/home/linoor/virtualenvs/LegalStart/project/local/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
       return self.cursor.execute(sql, params)
   ProgrammingError: relation "django_redirect" does not exist
   LINE 1: ...ct"."old_path", "django_redirect"."new_path" FROM "django_re...
                                                                ^

   --------------------- >> end captured logging << ---------------------

我试过在django shell中做同样的事情,但它运行正常。

该项目使用South,我找到了一些我应该将这些行添加到project.py文件中的地方:

SOUTH_TESTS_MIGRATE = False
SKIP_SOUTH_TESTS = True

但它仍然无效。

你们有什么想法可能有什么不对吗?如果需要,我可以提供其他信息。

谢谢!

1 个答案:

答案 0 :(得分:0)

好的,问题是Django Mezzanine插件正在动态删除&#34; django.contrib.redirects&#34;来自INSTALLED_APPS。