Now I am doing unit tests for existing code. I ran into the following problem:
After running syncdb to create a test database, Django automatically populates several tables, such as django_content_type or auth_permissions.
Then imagine that I need to perform a complex test, for example, check user registration, which will require a table of data and the relationships between them.
If I try to use my entire existing database to create fixtures (this would be quite convenient for me) - I will get an error, for example here . This is because Django has already populated tables like django_content_type.
The next possible way is to use the django dumpdata --exclude option for syncdb tables already populated. But this is also not very good, because if I take the User and User Group objects from the db and User Permissions table, which was automatically created by syncdb, I can get errors, because the primary keys connecting them now indicate incorrectly. This is better described here in the fixture hell part, but the solution shown there doesn't look good)
The next possible diagram that I see is as follows:
- I am doing my tests; Django creates a test database, creates syncdb, and creates all of these tables.
- In my test setup, I delete this database by creating a new empty database.
- Loading a data dump from an existing database into test setup as well
source share