1.

What is migration in Django?

Answer»

In Django, migration is a way of applying changes made in models that are adding the field, deleting model, ETC. into a database. To manage database schema changes migrations are a great way. You will find Django has created migration files inside the migration folder for each model. Each table is mapped to the model. Most migrations are designed to be automatic, but you need to know when to migrate, and when to run migrations.

Django has various commands to interact with migrations and Django's handling of a database schema. These commands perform migration-related tasks. After creating models you can use these commands.

  • makemigration - This command is used to create a migration file.
  • migrate - This command CREATES a table ACCORDING to the schema defined in migration file.
  • sqlmigrate - This command is used to SHOW a raw SQL query of the APPLIED migration.
  • showmigrations - This command list all the migrations and their status.


Discussion

No Comment Found