Migrations in NestJS help manage database changes safely. You write a migration class with up() to apply changes and down() to undo them. When you run the migration command, the system executes up(), updates the database schema, and records the migration in a history table. This history prevents running the same migration twice. If needed, you can rollback by running down(), which reverts the changes and updates the history. This process keeps your database structure consistent with your code. The execution table shows each step: starting migration, applying changes, updating history, and rolling back if necessary. Variables like the database schema and migration history change accordingly. Remember, both up() and down() are important for safe migrations.