Laravel Rollback Specific Migration – Tuts Make

1. First, you need to find the name of the migration you want to rollback. You can do this by running the following command in your terminal:

php artisan migrate:status

2. Once you have the name of the migration, you can rollback the specific migration by running the following command in your terminal:

php artisan migrate:rollback –step=1 –path=database/migrations/

Replace with the name of the migration you want to rollback.

3. Finally, you can check the status of your migrations again by running the following command in your terminal:

php artisan migrate:status
[ad_1]

To rollback specific migration for a specific table in Laravel; In this tutorial, you will learn how to rollback specific or last migration for a specific table in Laravel apps.

Rollback Specific Migration Laravel

Using the following steps, you can rollback specific or last migration for specific tables in laravel apps:

  • Step 1: Understand Database Migrations in Laravel

  • Step 2: See Available Migrations
  • Step 3: Rollback Specific Migration
  • Step 4: Laravel Rollback All Migrations
  • Step 5: Verify Specific Migration

Step 1: Understand Database Migrations in Laravel

Before using any migration command in Laravel, get to know about that command. Because the migration command in Laravel directly modifies your database tables using the database schema.

Step 2: See Available Migrations

Now, open your terminal or command prompt and go to your Laravel project root directory. Then execute php artisan to see the list of available commands related to migration.

php artisan migrate:status

Step 3: Rollback Specific Migration

If you want to rollback a specific migration for a specific table in Laravel apps. So, open the terminal or command prompt and execute the following command into it to rollback specific migration in laravel apps:

php artisan migrate:rollback --step=1 --batch=<batch_number>

Replace <batch_number> with the batch number of the migration you want to rollback. The --step=1 option ensures that only one migration is rolled back.

For example, if the batch number of the migration you want to rollback is 4, the command will be:

php artisan migrate:rollback --step=1 --batch=4

Step 4: Laravel Rollback All Migrations

If you want to rollback all migrations, which means resetting all migrations and starting fresh, you can use the migrate:reset command in Laravel. So, open your terminal or cmd and execute the following command into it to roll back all migrations and remove the migration entries from the migrations table:

php artisan migrate:reset

Step 5: Verify Specific Migration

Once you have executed the above rollback migration command, you should be able to see the result displayed on your terminal. And another option is that you can verify its execution by checking the database for any changes specified in the migration file.

Conclusion

That’s it; In this tutorial, you have learned how to rolback specific and all migration for tables in Laravel apps.

Recommended Tutorials

[ad_2]

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00