10.5 Putting It All Together

A migration is a file or script that modifies the database. Typically, our goal when using a migration is to reflect in our models any changes we’ve made to the structure of our data. The typical workflow for a schema migration is thus as follows:

1. Modify the model.

2. Generate or create the migration.

3. Apply the migration.

With a data migration, given that we are not modifying the migration, the workflow is simply to create and apply the migration.

In Django, a migration is defined by its dependencies and its operations. The dependencies tell Django what we expect to have already happened in the database, while the operations declaratively list the changes we wish to make. Django supplies 16 operations for us ...

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.