How to Rollback a Specific Migration in Laravel

Rollback a Specific Migration in Laravel

To rollback a specific migration in Laravel, “pass the –step argument to the migrate:rollback command.”

Here’s how to rollback the last batch of migrations by one step:

  1. Navigate to your Laravel project root directory.
  2. Run the following command:
    php artisan migrate:rollback --step=1

The –step option allows you to specify how many batches of migrations you want to roll back. In this case, specifying –step=1 will roll back the last batch.

Note: It’s always a good practice to back up your database before rolling back any migrations, especially in a production environment.

You can rollback and re-migrate a limited number of migrations by providing the step option to the refresh command.

For example, the following command will rollback & re-migrate the last two migrations:

php artisan migrate:refresh --step=2

You can roll back a limited number of migrations by providing the step option to the rollback command.

For example, the following command will rollback the last three migrations:

php artisan migrate:rollback --step=3

That’s it!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.