# Testing when connecting to existing database

**URL:** <https://forum.djangoproject.com/t/testing-when-connecting-to-existing-database/29544>\
**Category:** Mystery Errors\
**Created:** [March 27, 2024, 10:07am UTC](https://forum.djangoproject.com/t/testing-when-connecting-to-existing-database/29544 "2024-03-27T10:07:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThePix](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/thepix/32/13866_2.png) [@ThePix](https://forum.djangoproject.com/u/ThePix)\
**Post date:** [March 27, 2024, 10:07am UTC](https://forum.djangoproject.com/t/testing-when-connecting-to-existing-database/29544/1 "2024-03-27T10:07:40Z")

</div>

I am creating a new project to connect to an existing PostgreSQL database. I have successfully connected, and get get data, write to it, etc.

However, when it comes to running tests, they fail if they try to access the database.

```auto
Found 1 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
E
======================================================================
ERROR: setUpClass (cylinders.tests.BatchProductModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\django\db\backends\utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.UndefinedTable: relation "locations" does not exist
LINE 1: INSERT INTO "locations" ("name", "alias", "loc_type", "creat...
                    ^

```

It appears to create the test database okay, but it fails to find the table in there.

I ran the test with --keepdb, and took a look at the test database, and it has only the default tables in there; none of my models are there.

I guess an issue with migrations, which I just did not bother with at first, so after some research I did:

```auto
python manage.py makemigrations
python manage.py migrate --fake-initial

```

But still none of my tables in the test database. So where do I go from here?

[Not sure if “mystery errors” is the right place for this, but seems closer than the other options]
