laravel 4 artisan -- how to rollback to a specific migration state? laravel 4 artisan -- how to rollback to a specific migration state? laravel laravel

laravel 4 artisan -- how to rollback to a specific migration state?


I am afraid, you cannot do this directly.

You can:1, Rollback The Last Migration Operation (all migrations ran in the last batch)

php artisan migrate:rollback

2, Rollback all migrations

php artisan migrate:reset

3, Rollback all migrations and run them all again

php artisan migrate:refresh  php artisan migrate:refresh --seed

In your situation, modify b.php and it's up() method, then execute artisan migrate:refresh command.


There's a way to hack it by manually editing the database. In the migrations table change the batch column by giving the last migration a different batch number. Be aware that they are in increasing order, so edit accordingly. This tracks which migrations were applied separately.

Then run artisan:rollback and it will undo the last "batch".

So if you want to separate them all, then start from the top and give each 1,2,3,4,5 and so on... You can see that it is easily scriptable, and you can make an artisan command if you wish to separate all your migrations.


In my experience. I never do migrate:rollback. I would usually create another migration that does all the changes i need to "undo/rollback" the previous migrations.

This way you can be flexible if you want to rollback 2-x steps back, you can just create a new migration to effect the changes you want and then run the new migration by php artisan migrate.