Mike
Mike

Reputation: 429

psycopg2.errors.DuplicateTable: relation "app_appfile" already exists

I use postgres as DB for my project. I would like to make and run some test in my test.py file with sqlite DB. I change my settings.py file to do that with sqlite3 db, but when I try to run my simple test by python manage.py test I got this message:

Creating test database for alias 'default'... Got an error creating the test database: database "test_db" already exists

Type 'yes' if you would like to try deleting the test database 'test_db', or 'no' to cancel: yes Destroying old test database for alias 'default'...

After 'yes' I got it

django.db.utils.ProgrammingError: relation "app_appfile" already exists

my app/test.py

from rest_framework.test import APITestCase
from rest_framework.test import APIClient
from . models import Level

class SearchTest(APITestCase):

    def test_find_out(self):
        self.assertEqual(2, 2)
        

my settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': NAME,
        'USER': USER,
        'PASSWORD': PASSWORD,
        'PORT': PORT,
        'TEST': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': 'test_db',
        }
    }
}
SOUTH_TESTS_MIGRATE = False

I can see the same problem on the Internet but its solution doesn't work for me

Upvotes: 0

Views: 994

Answers (1)

Nnaemeka Daniel John
Nnaemeka Daniel John

Reputation: 464

Your previous test run probably didn’t clean up well, you should try clearing any existing test database by running python manage.py flush and deleting your test database file manually by running rm test_db then finally, try running your tests again using python manage.py test.

Upvotes: 0

Related Questions