Sunday, November 17, 2024
Google search engine
HomeLanguagesLaravel Rollback Specific Migration

Laravel Rollback Specific Migration

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

RELATED ARTICLES

Most Popular

Recent Comments