Django tests: how to specify the apps whose databases I want to use?

470 views Asked by At

My default database is not being migrated into Django's test database. A database is being created with default tables that Django uses to log tests (such as django_content_type and django_admin_log), but not my app's tables.

When I run the tests with a verbosity level of 3 (-v 3), I see that my app is categorized under Synchronizing apps without migrations... which confirms that the migrations aren't being performed.

I don't, however, know how to tell Django's tests to migrate my app's database tables. I can output python manage.py makemigrations easily but apparently that doesn't carry over to the tests.

What am I missing?

Thank you!

Edit: Sorry, I meant the relations are not being created. I want to test views which rely on models in the database. In order to do so, I'm uploading fixtures (to not deal with data on production). However, when I try to upload a fixture I get a relation "mymodel" does not exist error.

1

There are 1 answers

4
vmonteco On BEST ANSWER

Django's tests are designed to create a test database to perform tests.

I think that making your tests depend of a prod database is a bad idea. You should design your tests to cover as many cases as possible, not to check if it works with your current database (which can evolve).

Here are some pages about testing with django 1.8 :

https://docs.djangoproject.com/en/1.8/intro/tutorial05/

https://docs.djangoproject.com/en/1.8/topics/testing/