title: Access Django Test Database
body: <p>I have an API running on Heroku and would like to be able to test it using the test database. My problem I have is that the TestCase setUp(self) method adds the data to an automatically created test database. Then my tests send a POST request to the locally running version of itself. That code then is just using the regular default database instead of the test database the tests are running in.</p>
  
  <p>Here's some code and what I've tried.</p>
  
  <p>In my main settings.py I have named my database like so</p>
  
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.sqlite3',
          'NAME': 'theOneTrueDB',
      }
  }
  </code></pre>
  
  <p>And I read here (<a href="https://docs.djangoproject.com/en/3.0/topics/testing/overview/#the-test-database" rel="nofollow noreferrer">https://docs.djangoproject.com/en/3.0/topics/testing/overview/#the-test-database</a>) that </p>
  
  <blockquote>
    <p>The default test database names are created by prepending test_ to the value of each NAME in DATABASES.</p>
  </blockquote>
  
  <p>So I figured in my views file for one of my apps I could just do
  Tenant.objects.using('test_theOneTrueDB').all() and that would work but it says</p>
  
  <blockquote>
    <p>django.db.utils.ConnectionDoesNotExist: The connection test_theOneTrueDB doesn't exist</p>
  </blockquote>
  
  <p>I have also tried </p>
  
  <pre><code>Tenant.objects.using('test_default')
  </code></pre>
  
  <p>and many other things. I am lost. I would also be okay with setting up another database and then using that in the setup with </p>
  
  <pre><code>Tenant.objects.save(using='theOneTrueDBTest)
  </code></pre>
  
  <p>or something like that.</p>
  
  <p>Any help would be appreciated!</p>
  
  <p>EDIT:
  I know have my settings looking like this</p>
  
  <pre><code>DATABASES = {
      'default': {
          'NAME': 'theOneTrueDB',
          'ENGINE': 'django.db.backends.sqlite3',
      },
      'other': {
          'NAME': 'theOneTrueTest',
          'ENGINE': 'django.db.backends.sqlite3',
      }
  }
  </code></pre>
  
  <p>but then if I try to save to the other database like this</p>
  
  <pre><code>tempPM.save(using='other')
  </code></pre>
  
  <p>Then I get this error</p>
  
  <blockquote>
    <p>AssertionError: Database queries to 'other' are not allowed in this test. Add 'other' to API.tests.TenantLogin.databases to ensure proper test isolation and silence this failure.</p>
  </blockquote>