In this article, we will see how to roll back specific migrations in laravel. We will learn how to last migration revert/revoke in laravel 6, laravel 7, laravel 8, and laravel 9. Also, you can roll back all migration in laravel using the command line. So, we will explain how to roll back database migration using the laravel migration command.
Laravel migrations are like version control for your database, allowing your team to define and share the application's database schema definition.
So, let's see rollback specific migration laravel 6/7/8/9, how to delete the last migration file in laravel, and roll back all migrations laravel.
Using the rollback artisan command will roll back the latest migration. This command roll back the last "batch" of migrations. It includes multiple migrations files.
php artisan migrate:rollback
Using the --step artisan command will roll back the limited number of migration steps to roll back migrations.
php artisan migrate:rollback --step=3
The above command will roll back the last three migrations.
Using the reset artisan command will roll back all migrations.
php artisan migrate:reset
Using the --path artisan command will create or remove migrations for custom path locations. --path command required full path of file location.
php artisan migrate:rollback --path=/database/migrations/your-specific-migration-file-name.php
php artisan migrate:rollback --path=/database/migrations/2014_10_12_000000_create_users_table.php
Using the refresh artisan command will roll back all migrations and re-creates the entire database.
php artisan migrate:refresh
Also, you can roll back and re-migrate a limited number of migrations with the help of the step option with the refresh command.
php artisan migrate:refresh --step=3
Using the fresh artisan command will drop all database tables and then create new fresh migrations.
php artisan migrate:fresh
You might also like:
We've detected that you are using AdBlock or some other adblocking software which is preventing the page from fully loading.
We need money to operate the site, and almost all of it comes from our online advertising.
Please add websolutionstuff to your ad blocking whitelist or disable your adblocking software.