Django: How to keep db structure without data after running tests?

Viewed 1413

I want to use the --keepdb option that allow to keep the database after running tests, because in my case, the creation of the dabatase takes a while (but running tests is actualy fast)

However, I would like to keep the database structure only, not the data. Each time a run tests, I need an empty database.

I know I could use tearDown method to delete each object created, but it is a tedious and error-prone way to do. I just need to find a way to tell Django to flush the whole dabatase (not destroy it) at the end of the unit tests.

I have thinking of making a very simple script that:

  1. Run the tests keeping the db: manage.py test --keepdb
  2. run manage.py flushdb --database test_fugodb

However, with 2nd step, I got a django.db.utils.ConnectionDoesNotExist: The connection test_fugodb doesn't exist. What is the name of this test db? I took the one displayed when running tests:

What's wrong? Thanks!

1 Answers
Related