Laravel Rollback Specific Migration

Laravel Rollback Specific Migration

If you want to reset all or specific tables using migration in Laravel, then in this tutorial, you will see how to reset specific or all tables in a database using the rollback migration command in Laravel10|9|8 apps.

Rollback Specific Migration Laravel 10|9|8

Using the following steps, you can rollback specific or last migration for specific tables in laravel 10|9|8 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

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *