Sobes.tech
Junior — Middle

What commands do you use when performing database migrations in Django?

sobes.tech AI

Answer from AI

In Django, the following main commands are used for working with database migrations:

  • python manage.py makemigrations — creates new migrations based on changes in models.
  • python manage.py migrate — applies migrations to the database, updating its structure.
  • python manage.py showmigrations — displays a list of all migrations and their status (applied or not).
  • python manage.py sqlmigrate <app_name> <migration_name> — outputs the SQL code that will be executed when applying the migration.

Example:

python manage.py makemigrations
python manage.py migrate