to rollback only :
Rolled back: 2015_05_15_195423_alter_table_web_directories
php artisan migrate:rollback
, 3 of my migration are rolling back.
Rolled back: 2015_05_15_195423_alter_table_web_directories Rolled back: 2015_05_13_135240_create_web_directories_table Rolled back: 2015_05_13_134411_create_contacts_table
both of my web_directories
and my contacts
table unintentionally. I never want that to happen, and if I can rollback only that specific one, this disaster will never happen.
You can rollback your migration by using rake db:rollback with different options. The syntax will be different according to your requirements.
To run the specific migration in Laravel, you need to use --path option with the php artisan migrate command. Let's take a simple example, we have '2019_12_04_131405_create_payments_table. php' migration in the database/migrations directory and we would like to run this migration.
Rollback one step. Natively.
php artisan migrate:rollback --step=1
And here's the manual page: docs.
No way to do without some hassle. For details, check Martin Bean's answer.
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.
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