DjancoCon 2021 WorkShop | Migrations and understanding Django's relationship with its database

DjancoCon 2021 WorkShop | Migrations and understanding Django's relationship with its database David Wobrock

Migrations are a very convenient aspect of the Django framework. They allow making changes to your models when needed, and impact the database schema iteratively in a smooth and integrated manner. No need to have a deep knowledge of SQL, be a database expert nor administrator - it just works. Or at least, most of the time.

The generated migration files reflect the model changes from one version to the next, and Django logically expects these migrations to be applied for the database connections to work. The required synchronicity between code and database schema is the root of some issues one might encounter when using Django. We will dive into these issues during this workshop.

We will first explore in which cases one can run into these migration problems, and how they are intrinsically linked to this synchronicity. This will be done by creating a Django project and adding toy features to it, like any developer would do during the workday. After defining the concept of backward incompatible migrations, we will also expose some example operations and why they can turn out dangerous. The workshop will go about suggesting some existing solutions to these problems: we will manually fix such issues in development, but also explore how to prevent them from happening in a large-scale infrastructure with multiple servers. Hopefully giving the attendees a better grasp of what is happening under the hood when something seems off with models and migrations.

Date Added: September 19, 2024

Watch Video