Django and slow migrations: how to quickly get an empty database?

I have a Django 1.8 codebase with 14 applications and ~ 90 tables. Most applications have 1-2 migrations.

I noticed that most of the time spent launching the test suite is spent on applying migration. It may take> 5 minutes to apply all migrations to an empty database.

It takes 1-2 seconds to create a database and import an SQL dump into it to achieve the same state of the database.

We do not use a standard approach manage.py test, so using --keepdbis most likely not an option for me. (And even so, I would have to pay the price of migration at least once per turn.)

What I'm looking for is a way to create an empty database according to the latest model definitions. For example, initial migration, as if all other migrations did not exist, would have the right effect.

Is there a known way to achieve this? Or is there an alternative, well-known approach to the problem of migration that lasts a long time during trials?

+4
source share
1 answer

There is a good application called django-test-without-migrations https://pypi.python.org/pypi/django-test-without-migrations/ . It does exactly what you want: it creates a database using the latest model definitions.

( )

python manage.py test --nomigrations

python manage.py test -n

.

+8

Source: https://habr.com/ru/post/1616095/


All Articles