Laravel how to roll back one migration
Learn how to rollback a single Laravel migration, with a step-by-step example.
Rolling Back a Migration in Laravel
In Laravel, rolling back a migration means reverting the database to a previous state. This is useful when you have made changes to the database which you now want to undo. To do this, you will need to use the Artisan command line interface.
First, you need to decide which migration you want to roll back. To do this, you can type the following command in the terminal:
php artisan migrate:status
This will show you a list of migrations which have been run, and their respective IDs. Find the ID of the migration which you want to roll back and make a note of it.
Once you have the migration ID, you can roll it back using the following command:
php artisan migrate:rollback --step=id
In this command, replace the id
with the ID of the migration you want to roll back. For example, if the migration ID is 12345
, the command would be:
php artisan migrate:rollback --step=12345
Once the command is executed, the migration will be rolled back. You can verify that the rollback has been successful using the migrate:status
command again.