I have a Django 1.8 codebase with 14 apps and ~90 tables. Most apps have 1-2 migrations.
I noticed that most of the time spent running a test suite is spent on applying migrations. It may take >5 minutes to apply all migrations to an empty database.
It takes 1-2 seconds to create the database and import an SQL dump into it to achieve the same database state, though.
We are not using the standard manage.py test
approach, so using --keepdb
is likely not an option for me. (And even it it was, I'd have to pay the price of the migrations at least once per run.)
What I'm looking for is a way to create an empty database according to the latest models definitions. For instance, making an initial migration as if all other migrations don't 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 migrations taking a long time during tests?
There is a nice app called django-test-without-migrations https://pypi.python.org/pypi/django-test-without-migrations/. It does just what you want: creates database using latest models definitions.
After installation and configuration (which is very simple) you just run
python manage.py test --nomigrations
or
python manage.py test -n
And it simply works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With