I want
to rollback only :
Rolled back: 2015_05_15_195423_alter_table_web_directories
I run
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
I delete
both of my web_directories
and my contacts
table unintentionally.
Sadly, I never want that to happen, and if I can rollback only that specific one, this disaster will never happen.
I hope
someone can teach me how to prevent this from happening again.
Any recommendation will be much appreciated.
If you want modify original migration file and migrate it again, you can use this package to migrate. (Applicable to Laravel 5.4 or later)
First, install package in your Laravel project:
Register command at
app/Console/Kernel.php
:Now, run this command to migrate your file
Use command "php artisan migrate:rollback --step=1" to rollback migration to 1 step back.
For more info check the link :- https://laravel.com/docs/master/migrations#running-migrations
Laravel 5.3+
Rollback one step. Natively.
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.
It might be a little late to answer this question but here's a very good, clean and efficient way to do it I feel. I'll try to be as thorough as possible.
Before creating your migrations create different directories like so:
Then, when creating your migrations run the following command (using your tables as an example):
or
or
The commands above will make the migration file within the given directory path. Then you can simply run the following command to migrate your files via their assigned directories.
*Note: You can change batch_1 to batch_2 or batch_3 or whatever folder name you're storing the migration files in. As long as it remains within the database/migrations directory or some specified directory.
Next if you need to rollback your specific migrations you can rollback by batch as shown below:
or
or
Using these techniques will allow you more flexibility and control over your database(s) and any modifications made to your schema.
Rollback one step. Natively.
Rollback two step. Natively.
If you can't do what is told by @Martin Bean, then you can try another trick.
Create a new migration and on that file in up() method insert what's in down() method of the migration you want to rollback and in down() method insert what's in up() method.
e.g if your original migration is like this
then in new migration file do this
and then run the migrate, it will delete the table. and if you again want that back just rollback it.