Rollback one specific migration in Laravel
Every time you rollback you get the last batch of migration. use the command
php artisan migrate:rollback --step=1
Best way is to create a new migration and make required changes in that.
Worst case workaround (if you have access to DB plus you are okay with a RESET of that table's data):
- Go to DB and delete/rename the migration entry for
your-specific-migration
- Drop the table created by
your-specific-migration
- Run
php artisan migrate --path=/database/migrations/your-specific-migration.php
This will force laravel to run that specific migration as no entry about it exists in Laravel's migration history
UPDATE: The Laravel way (Thanks, @thiago-valente)
Run:
php artisan migrate:rollback --path=/database/migrations/your-specific-migration.php
and then:
php artisan migrate
This will re-run that particular migration
If you look in your migrations
table, then you’ll see each migration has a batch number. So when you roll back, it rolls back each migration that was part of the last batch.
If you only want to roll back the very last migration, then just increment the batch number by one. Then next time you run the rollback
command, it’ll only roll back that one migration as it’s in a “batch” of its own.
Alternatively, from Laravel 5.3 onwards, you can just run:
php artisan migrate:rollback --step=1
That will rollback the last migration, no matter what its batch number is.
Laravel 5.3+
Rollback one step. Natively.
php artisan migrate:rollback --step=1
And here's the manual page: docs.
Laravel 5.2 and before
No way to do without some hassle. For details, check Martin Bean's answer.