django-tenant-schemas icon indicating copy to clipboard operation
django-tenant-schemas copied to clipboard

Test fails with ProgrammingError: relation does not exist

Open fablet opened this issue 10 years ago • 3 comments
trafficstars

I am trying to run tests on my own project. I have a very simple test case set up that inherits from TenantTestCase but errors out with ImportError: Failed to import test module, and ProgrammingError: relation does not exist.

Any help or advice would be vastly appreciated.

class MyTest(TenantTestCase):
        def test_address_short_address_all(self):
            address = AddressFactory()
            self.assertIn(address.address_line1, address.short_address)
            self.assertIn(address.city, address.short_address)

traceback:

ERROR: calendr.tests (unittest.loader.ModuleImportFailure)
ImportError: Failed to import test module: calendr.tests
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/loader.py", line 254, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name
    __import__(name)
  File "/home/fableturas/code/cindercal/calendr/tests.py", line 19, in <module>
    from views import CalendarView
  File "/home/fableturas/code/cindercal/calendr/views.py", line 27, in <module>
    from forms import AddressFormSet, BidForm, CustomerFormSet, EventFormSet
  File "/home/fableturas/code/cindercal/calendr/forms.py", line 152, in <module>
    class BudgetForm(Form):
  File "/home/fableturas/code/cindercal/calendr/forms.py", line 156, in BudgetForm
    budget, created = Resource.objects.get_or_create(title="Daily Budget")
  File "/home/fableturas/.virtualenvs/cindercal/local/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
    return getattr(self.get_queryset(), name)(_args, *_kwargs)
  File "/home/fableturas/.virtualenvs/cindercal/local/lib/python2.7/site-packages/django/db/models/query.py", line 405, in get_or_create
    return self.get(**lookup), False
  File "/home/fableturas/.virtualenvs/cindercal/local/lib/python2.7/site-packages/django/db/models/query.py", line 328, in get
    num = len(clone)
  File "/home/fableturas/.virtualenvs/cindercal/local/lib/python2.7/site-packages/django/db/models/query.py", line 144, in **len**
    self._fetch_all()
  File "/home/fableturas/.virtualenvs/cindercal/local/lib/python2.7/site-packages/django/db/models/query.py", line 965, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/home/fableturas/.virtualenvs/cindercal/local/lib/python2.7/site-packages/django/db/models/query.py", line 238, in iterator
    results = compiler.execute_sql()
  File "/home/fableturas/.virtualenvs/cindercal/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 829, in execute_sql
    cursor.execute(sql, params)
  File "/home/fableturas/.virtualenvs/cindercal/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/fableturas/.virtualenvs/cindercal/local/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/fableturas/.virtualenvs/cindercal/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
ProgrammingError: relation "calendr_resource" does not exist
LINE 1: ...r_resource"."id", "calendr_resource"."title" FROM "calendr_r...

fablet avatar Oct 26 '15 21:10 fablet

@fablet Are you having auto_create_schema = False in your tenant model? If yes, TenantTestCase won't work directly because it's won't migrate the tenant models automatically.

nikhiln avatar Nov 23 '16 11:11 nikhiln

Try running the comman with ./manage.py test tenant_schema.test <model_to_test>

freewayz avatar Nov 06 '17 11:11 freewayz

Any chance you have figured this out?

michaeljonaitis avatar Mar 19 '20 18:03 michaeljonaitis