In Laravel, migration rollback is a way to undo the last batch of migrations that were applied to the database. This can be useful during development or testing if you need to revert your database to a previous state. Here's how you can perform a migration rollback:
You can use the migrate:rollback
Artisan command to rollback the last batch of migrations:
php artisan migrate:rollback
This command will execute the down()
method for each migration that belongs to the last batch, effectively undoing the changes made by those migrations. By default, Laravel rolls back the last batch of migrations that were run.
If you want to rollback a specific number of batches of migrations, you can use the --step
option:
php artisan migrate:rollback --step=2
This command will rollback the last two batches of migrations.
If you want to rollback all migrations and start fresh from a specific migration, you can use the migrate:reset
or migrate:rollback --step=1
command:
php artisan migrate:reset
php artisan migrate:rollback --step=1
This command will rollback all migrations, effectively undoing all changes made to the database schema.
Alternatively
, you can rollback
to a specific migration by specifying the migration's class name:
php artisan migrate:rollback --path=database/migrations/2022_03_13_123456_create_users_table.php