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?
score:8
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.
Credit To: stackoverflow.com
Related Query
- Django and slow migrations: how to quickly get an empty database?
- How do I get new Database changes since last login using Django and Python?
- How can I maintain Django database entries after making migrations and pushing changes to Git?
- Django : How to get longitude and latitude from google maps user selected adress and save to database
- Django app view - how to get an entry from the django database in the url and to obtain more information from the database for the view?
- how can i get id of one class object, in another class and store in the database - Django
- How to get Django and ReactJS to work together?
- How do you perform Django database migrations when using Docker-Compose?
- Django database query: How to get object by id?
- How do you get PyPy, Django and PostgreSQL to work together?
- How do I get odd and even values in a Django for loop template?
- How to view database and schema of django sqlite3 db
- django 1.7 migrations -- how do I clear all migrations and start over from scratch?
- How to set the default of a JSONField to empty list in Django and django-jsonfield?
- how to create an empty queryset and to add objects manually in django
- How can I get the URL (with protocol and domain) in Django (without request)?
- How to store IP address in the database and django admin
- how do I get django runserver to show me DeprecationWarnings and other useful messages?
- How to merge consecutive database migrations in django 1.9+?
- How to get Interdependent dropdowns in django using Modelform and jquery?
- How do I create a new database for an existing App using Django South and set default values?
- How to get a response of multiple objects using rest_framework and Django
- how to get django to return both an HttpResponse AND render a different template
- How to decode token and get back information for djangorestframework-jwt packagefor Django
- django how to get the 0th item from a possibly empty list
- How to use different database engines in Django for testing and production
- django how to get old value and new value in pre_save fucntion
- Django templates: how to avoid empty lines with include and load?
- How do I get django celery to write to the test database for my functional tests?
- How do I get Django 1.5 Custom User Model and Social Auth to work?
More Query from same tag
- Django ORM: Chaining aggregated querysets into one
- Django UserManager create_user failing with 'NoneType' object not callable
- Django celery worker error on ec2 trying to start daemon process with systemd
- How do i check for duplicates in django sqlite database
- Django, Python: Best way to parse a CSV and convert to Django model instances
- ERROR: Could not build wheels for backports.zoneinfo, which is required to install pyproject.toml-based projects
- Python database WITHOUT using Django (for Heroku)
- How to get the request-id from snmp response
- Django Shell No module named settings
- Django-Compressor does nothing
- How to enforce user to enter a datefield in DD-MM-YYYY format, and timefield in 'HH:MM' format in django?
- How to securely connect to Azure redis from celery-django project?
- Django error: [Errno 60] Operation timed out
- Django: How to reduce size and increase cohesion of views
- How to set different permissions depending on the request method?