How To Roll back Specific Migration In Laravel

Websolutionstuff | Nov-11-2022 | Categories : Laravel MySQL

In this article, we will explore the process of rolling back specific migrations in Laravel, focusing on Laravel versions 6, 7, 8, 9, and 10. We will delve into how to revert or revoke the last migration, and you'll also learn how to roll back all migrations using command-line tools.

Laravel's migration system serves as a version control mechanism for your database, enabling you to define and share your application's database schema with your team.

Let's examine how to perform specific migration rollbacks in Laravel 6, 7, 8, 9, and 10, understand the process for deleting the last migration file, and explore the options for rolling back all migrations in Laravel.

Example:

Using the rollback artisan command will roll back the latest migration. This command roll back the last "batch" of migrations. It includes multiple migrations files.

php artisan migrate:rollback

 

Using the --step artisan command will roll back the limited number of migration steps to roll back migrations.

php artisan migrate:rollback --step=3

The above command will roll back the last three migrations.

 

Using the reset artisan command will roll back all migrations.

php artisan migrate:reset

 

Using the --path artisan command will create or remove migrations for custom path locations. --path command required full path of file location.

php artisan migrate:rollback --path=/database/migrations/your-specific-migration-file-name.php
php artisan migrate:rollback --path=/database/migrations/2014_10_12_000000_create_users_table.php

 

Using the refresh artisan command will roll back all migrations and re-creates the entire database.

php artisan migrate:refresh

Also, you can roll back and re-migrate a limited number of migrations with the help of the step option with the refresh command.

php artisan migrate:refresh --step=3

 

Using the fresh artisan command will drop all database tables and then create new fresh migrations.

php artisan migrate:fresh

 


You might also like:

Recommended Post
Featured Post
How to Convert PDF to Image in Laravel 10
How to Convert PDF to Image in...

Greetings, Laravel enthusiasts! Today, let's unravel a common challenge in web development – converting PDFs t...

Read More

Dec-22-2023

Laravel 10 Composer-runtime-api ^2.2 Error - Fixed
Laravel 10 Composer-runtime-ap...

In this article, we will see laravel/framework[v10.0.0, ..., v10.0.3] require composer-runtime-api ^2.2 error fixed...

Read More

Mar-07-2023

How To Install LAMP Server In Ubuntu 22.04
How To Install LAMP Server In...

In today's digital landscape, hosting dynamic websites and powerful web applications is essential for individuals an...

Read More

Jul-31-2023

How to Add Date Picker in React JS using react-datepicker
How to Add Date Picker in Reac...

A date picker is a crucial component in many web applications, enabling users to select dates conveniently. React, a pop...

Read More

Sep-11-2023