Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
rollback specific migration in laravel

How to rollback specific migration in laravel ?

Aman Jain, March 6, 2022February 8, 2024

In this article we will learn rollback specific migration in laravel, in our recent article i wrote about creating migration in laravel and sometimes after creating migration we want to rollback specific migration laravel so in this article i will show you to rollback a specific migration in laravel. Laravel artisan have multiple options to rollback the migration like we can rollback all migrations, we can rollback last n number of migration using step option and in the same way we can rollback all specific rollback using reset option.

Rollback specific migration in laravel

In relational databases rollback is a technique to revert back the database operation in previous state. In the same way laravel maintains it migrations in file and database, and we can rollback the operation to its previous state using artisan command.

However there is no direct command to rollback the specific migration but we can use this blow tricks to rollback the migration.

Steps to rollback specific migration

Step 1 : Open database and check migrations table

In this step we will open our database using any tool like phpMyAdmin or command line then check migrations table.

Screenshot 2022 03 06 at 8.17.43 PM
Migration table

As you can see we have migration table and i want to rollback 2022_02_15_174050_add_status_movies_table

Step 2 : Change batch number to last number

Now, change the batch number of 2022_02_15_174050_add_status_movies_table to last number of batch number , In our example last number is 8 so change the 2022_02_15_174050_add_status_movies_table batch to 9

92022_02_15_174050_add_status_movies_table9
Change batch number

Step 3 : Run artisan rollback command

Run the artisan command rollback to make the changes

php artisan migrate:rollback --step=1

So here we are rollback the last batch which is 9

Rolling back: 2022_02_15_174050_add_status_movies_table


Rollback last migrations using step option

We can also rollback last migration using the step option in artisan command, step option accept numeric parameter to rollback last migrations. For example if --step =2 then it means it will rollback last two migrations.

here is the command

php artisan migrate:rollback --step=3

Rollback last batch migrations

We can also rollback last batch of migration using the migration rollback command without any options as below

Here is the command

php artisan migrate:rollback

Rollback all migrations and reset database

We can also rollback all migration and also can reset the database migration to start point using artisan migration:reset command

Here is the command

php artisan migrate:reset

Rollback all and Re run all migrations

refresh option is used to rollback all migration and it runs again migration command to re create the database

Here is the command

php artisan migrate:refresh

Related

Uncategorized laravelmigrationrollback

Post navigation

Previous post
Next post

Related Posts

Uncategorized dependency injection angular

What is Dependency Injection in Angular?

June 20, 2021November 8, 2023

In a simple term we can say dependency injection in angular are created once at the time of initialisation of service or component then throughout the application we can reuse same object without re-initialisation. So, this is clear now advantage of dependency injection is to not creating the object in…

Read More
Uncategorized confirm password validation in Laravel

Password and confirm password validation in Laravel

January 26, 2022November 10, 2023

There is many ways to check the password and confirm password validation in laravel. we can match password using the equals to operator but in that case we need to work as core PHP. So In laravel we have Validation library to create the validation rules. Laravel itself provides multiple…

Read More
Laravel Create database connection in laravel

How to make database connection in Laravel 8 ?

December 14, 2021February 22, 2024

Laravel comes with first party support for several database drivers. Laravel gives much better flexibility in terms of using the RDBMS based databases. Laravel supports MySQL, PostgreSQL, SQLite and SQL Server by default but if you want to make connection with Mongo or other database then you need to install…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
  • Understanding High Vulnerabilities in Software: A Week of Insights
  • Blocking Spam Requests with LaraGuard IP: A Comprehensive Guide
  • Enhancing API Development with Laravel API Kit
  • Exploring the Future of Web Development: Insights from Milana Cap
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version