Rollback Your Database Migration In Laravel

Hi artisan now i am going to discuss about laravel database migration. So this example is going to focus on how to rollback migration in laravel. I wanna share with you how to revert migration in laravel. That mearn basicallly I’m going to show you about laravel migration rollback example.

So i hope you can understand a concept of laravel migration rollback step 1. I will share simple example of how to rollback database migration using laravel migrate command. So hope you can use this commands with laravel 6, laravel 7 and laravel 8 version in your running application.

 

Create Table

We need table to test our database rollback command. So create those below tables

php artisan make:migration create_posts_table
php artisan make:migration create_items_table
php artisan make:migration create_products_table

 

laravel-migration-rollback-example

Now migrate and create another table to test database rollback. So create it

php artisan make:migration create_football_table

 

create-football-table

 

Rollback Last Migration

Now you can rollback your last migration by the following command like below

php artisan migrate:rollback

 

After running the following command you will see the below output

 

roll-back-migration

Rollback Last Migrations with Step:

We can pass --step option with rollback number of migration from last. here it will rollback last two migration.

php artisan migrate:rollback --step=2

 

After running the following command you will see the below output

 

lollback-with-step-laravel

 

Rollback All Migrations:

You can also rollback your all migration. So just rollback all means it will reset all migration. so if you change anything on migration file then it will recreate and affect it.

php artisan migrate:reset

 

Output:

 

migrate-reset-command-laravel

 

Recommended : Build a SPA Authentication using Laravel Sanctum

 

Hope it can help you.

 

#laravel #migrations