V
V
Vasily Vorobyov2015-08-25 19:38:59
Django
Vasily Vorobyov, 2015-08-25 19:38:59

Why can't I start django testserver with fixtures?

I'm trying to run tests on a production base. Did the following:

./manage.py dumpdata --natural > dump.json
django-admin testserver dump.json

In response I receive
django.db.utils.IntegrityError: Problem installing fixture '/home/zuber/Projects/PCR/project/apps/bn/fixtures/real_db.json': Could not load contenttypes.ContentType(pk=1): UNIQUE constraint failed: django_content_type.app_label, django_content_type.model

What's the matter? After all, the base is created absolutely empty, where does the contenttypes come from? I can't live without contenttypes, because I'm testing permissions that are tied to specific contenttypes

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2015-08-27
@zuberok

When running tests, the database is not created completely empty, because Django does a few extra steps after running syncdb or migrate (in newer versions), such as calling the update_contenttypes method , which populates the ContentTypes table.
There are several options for solving the problem, but I suggest dumping the data with this line:
Thus, you will exclude data from the fixture, which is already created automatically every time the tests are run.
For further reading I recommend stackoverflow.com/questions/853796/problems-with-c...

D
Denis Demkin, 2021-01-31
@DemkinDenis

Change the key --naturalto--natural-foreign

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question