Q:

ProgrammingError: relation "django_redirect" does not exist when running django tests

I am trying to run a very simple test using django:
class 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)

Unfortunately each time I try to run it I get an error:
(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 << ---------------------

I've tried doing the same thing in the django shell and it works fine.
The project uses South and I found somewhere that I should add these lines to the project.py file:
SOUTH_TESTS_MIGRATE = False
SKIP_SOUTH_TESTS = True

But it still doesn't work.
Do you guys have any idea what might be wrong? I can provide additional info if needed.
Thanks!

A:

Ok, so the problem was Django Mezzanine addon which was dynamically removing the "django.contrib.redirects" from the INSTALLED_APPS.

