Making Django Migrations
Learn about migrations in Python Django and how to create them.
Understanding migrations in Django
Before we make migrations in our application, we must understand what they mean in Django and why they’re important. Previously, we created two models, House
and Checker
. Each model maps to a database table, and each model’s attribute represents a database field. Whenever we change these parameters, Django will implement the changes by migrations. Django helps us automatically make these changes in our database without writing any structured query language to populate or update these tables and fields.
Migrations in Django are possible with the help of an object-relational mapper (ORM), which provides tools that are necessary to manage our database over time. Some data in our database will not be static and changes can occur with time as people use our web application. Sometimes, it can lead to creating new models with different attributes as the problem we solve evolves or as new features are added. This will mean adding new tables and fields in our database. All these situations will require us to populate or update our database. With the help of the migration system in Django, we can effortlessly carry out this action without worrying about dropping tables, having conflicting data, or losing sensitive data. The migration system will compare the present states of our database ...