How Can I Rollback Specified Tables In Laravel With An Example

admin_img Posted By Bajarangi soft , Posted On 23-09-2020

In Laravel roll back will delete the new table created in database or the latest migration operation will be rollback.

How Can I  Rollback Specified Tables In Laravel With An Example

Rolling Back Migrations

To roll back the latest migration operation, you may use the rollback command. This command rolls back the last "batch" of migrations, which may include multiple migration files:
 

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


The migrate:reset command will roll back all of your application's migrations:

php artisan migrate:reset

 

Roll Back & Migrate Using A Single Command

The migrate:refresh command will roll back all of your migrations and then execute the migrate command. This command effectively re-creates your entire database:

php artisan migrate:refresh

// Refresh the database and run all database seeds... php artisan migrate:refresh --seed


You may roll back & re-migrate a limited number of migrations by providing the step option to the refresh command. For example, the following command will roll back & re-migrate the last five migrations:

php artisan migrate:refresh --step=5


Drop All Tables & Migrate

The migrate:fresh command will drop all tables from the database and then execute the migrate command:

php artisan migrate:fresh
php artisan migrate:fresh --seed

Related Post