Rollback a specific migration in Laravel

How To Rollback a specfic migration in Laravel

Many a time in our life as a Laravel Developer, there comes a situation where you’re in the middle (quite literally) of quite a few migrations that have already been created and migrated when you suddenly need to rollback a specific migration without losing the migrations created after this migration that you want to rollback.

So, obviously, we cannot run the following command in the terminal, otherwise, along with the migration we wish to rollback, it will also rollback any migrations created after it.

pho artisan:rollback

What we can do instead is, pass the relative path of the migration file using the path flag.

Consider the example below: we wish to roll back just the 2024_04_03_124522_create_stake_holders_table.php migration file without touching the migrations created after this migration file.

While inside your project’s root folder in the terminal, run the following command:

php artisan migrate:rollback --path=database/migrations/2024_04_03_124522_create_stake_holders_table.php
Specifific migration rolled back

As you can see in the screenshot above, running the command above removes specifically our 2024_04_03_124522_create_stake_holders_table.php migration file.

Share This Post

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe To my Future Posts

Get notified whenever I post something new

More To Explore