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, 2022November 8, 2023

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

Share this:

  • Facebook
  • X

Related

Uncategorized laravelmigrationrollback

Post navigation

Previous post
Next post

Related Posts

Uncategorized setup simple jQuery form validation

How to setup simple jQuery form validation?

September 15, 2021September 29, 2021

In this tutorial, we are going to learn jQuery form validation using jQuery validation plugin. this plugin have many features like to validate text, email, phone number , sync Ajax request etc. Let’s begin with step by step guide: Step 1: Create a html file Firstly we are going to…

Share this:

  • Facebook
  • X
Read More

What is httpd.conf and httpd-vhost.conf file in apache?

August 28, 2021August 28, 2021

https.conf is main file of apache web server to handle the requests. Apache httpd.conf file generally located at /etc/httpd/conf/httpd, /etc/apache2/ , /etc/apache2/sites-enabled/ in ubuntu. httpd.conf contains the information of server root and port used routing. httpd-vhost contains additional information of virtual host.

Share this:

  • Facebook
  • X
Read More
Uncategorized Custom middleware in laravel

How to create custom middleware Laravel 8

October 15, 2021November 6, 2023

In this tutorial we will going to learn custom middleware Laravel 8. Middleware are used to create a layer between request and response of the http request. it filters or create a logic before the request serve to the controller and also filter or modify the response. we can also…

Share this:

  • Facebook
  • X
Read More

Leave a ReplyCancel reply

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 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • 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

  • How to Call Controller Method from Another Controller in Laravel ?
  • How to Get Domain Name in Laravel ?
  • How to Append Query String to Route in Laravel ?
  • How to Append URL Query Params to Pagination Laravel ?
  • How to Get Today Records in Laravel ?
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version