Avi Kaminetzky
Avi Kaminetzky

Reputation: 1538

MySQL Test DB Failing

I set up a Django 2 app (and Python 3.6) with a remote MySQL DB (using mysqlclient), with proper permissions.

When I run my unit test, I get the following error: django.db.utils.ProgrammingError: (1146, “Table ‘test_<db>.<db>’ doesn’t exist”).

When I manually open the website at localhost, everything works fine.

Technically I could create a local dev DB for testing, but I would prefer that the test DB is created automatically.

EDIT

It seems like the issue was related to my tables not being managed by Django, see here.

Upvotes: 0

Views: 251

Answers (2)

Avi Kaminetzky
Avi Kaminetzky

Reputation: 1538

What worked for me:

Changing my tables to managed = True.

Deleting migration files (except __init__.py).

python manage.py makemigrations

python manage.py migrate

And now my unit tests are running.

Upvotes: 1

Mark Rogaski
Mark Rogaski

Reputation: 111

I believe this is a duplicate.

Django : Table doesn't exist

If the table is missing, make sure you've got the right migration file (python manage.py makemigrations) and that you've applied it (python manage.py migrate).

Upvotes: 1

Related Questions