How to Rollback Migration in Laravel?

Spread the love

Hello Guys,

This illustration provides a comprehensive guide on performing a rollback migration in Laravel. I’ll share with you the process of reverting a migration in Laravel. In this tutorial, we’ll explore an example of how to execute a Rollback Migration in Laravel, allowing you to grasp the fundamental concepts of Laravel migration reversal.

To begin, I’ll present a straightforward example of using the Laravel migrate command to undo a database migration. Furthermore, you’ll learn how to roll back either all migrations or a specific migration by utilizing the step option. Let’s delve into some basic instances to illustrate how migration rollback functions.

These instructions for Rollback Migration in Laravel are applicable to various Laravel versions, including Laravel 6, Laravel 7, Laravel 8, Laravel 9, and Laravel 10.

Also Read: how to Create Custom Artisan Command in LARAVEL

Created New Migrations:

php artisan make:migration create_posts_table

php artisan make:migration create_items_table

php artisan make:migration create_products_table

Rollback Last Migration:

php artisan migrate:rollback

Rollback Last Migrations using Step:

You have the option to indicate a rollback number for a migration when utilizing the “–step” parameter. This allows you to easily undo the last two migrations.

Also Read: How to Drop Soft Delete from Table using Migration in LARAVEL?

php artisan migrate:rollback --step=2

Rollback All Migrations:

Resetting all migrations will result in the complete loss of migration data. Consequently, any modifications made to the migration file will be reinitialized, potentially affecting your project.

Also Read: How to use laravel cookies – Get, Set, Delete with example

php artisan migrate:reset

Embrace the elite realm of Laravel insights – your compass to the best Laravel blog awaits.

Leave a Comment