How to remove migration in Laravel

Learn how to delete migrations in Laravel with an example. Understand the process and get rid of any unwanted migrations.

It is possible to remove migration in Laravel with a few easy steps. The first step is to delete the migration file from the database/migrations directory. To do this you can use the following command in your terminal:

rm -f database/migrations/migration-name.php

This command will delete the migration file from the migrations directory. After deleting the migration file, you will need to run a command to rollback the migration. The command for rolling back the migration is:

php artisan migrate:rollback

This command will rollback all migrations that have been executed since the last migration file was created. After rolling back the migration, you will need to remove the migration record from the migrations table. To do this you can use the following command:

php artisan migrate:reset

This command will remove all migration records from the migrations table. After resetting the migrations table, you will need to run a command to refresh the migrations table. The command for refreshing the migrations table is:

php artisan migrate:refresh

This command will refresh all the migrations in the migrations table. Finally, you will need to run a command to rebuild the migrations table. The command for rebuilding the migrations table is:

php artisan migrate:refresh --seed

This command will rebuild the migrations table and seed it with the necessary data. After running this command, the migration will be successfully removed from your application.

Conclusion

In conclusion, it is possible to remove migration in Laravel with a few easy steps. First, you need to delete the migration file from the database/migrations directory. After deleting the migration file, you will need to run a command to rollback the migration. After rolling back the migration, you need to remove the migration record from the migrations table. After resetting the migrations table, you need to run a command to refresh the migrations table. Finally, you need to run a command to rebuild the migrations table. By following these steps, you can successfully remove migration in Laravel.

Answers (0)