Say i got a.php
, b.php
, c.php
and d.php
migration classes files. How to rollback to a specific migration state, the state defined within b.php
for example, with artisan command ?
php artisan migrate:rollback. You may roll back a limited number of migrations by providing the step option to the rollback command. For example, the following command will roll back the last five migrations: php artisan migrate:rollback --step=5.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With