26.3.6 Using Migrations to Learn about Optimization

We could now jump into our views and begin optimizing our webpages there. Before we do, however, I want to draw your attention to our migration files.

By default, when you run tests (when, not if) Django creates a new database based on migrations files. Despite living in memory, this process can be quite time consuming. A fun exercise for learning to optimize code is to take the code in our migrations and attempt to speed them up. This exercise also provides the opportunity for us to use the Q object.

Info

It is possible to disable migrations during tests. If you have a large number of migrations, disabling them for your tests may be advisable.

When we programmed our Tag data migration in ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.