TestBike logo

Laravel rollback specific migration. Migrations are like version control for your database. Al...

Laravel rollback specific migration. Migrations are like version control for your database. Alternatively, from Laravel 5. Jul 21, 2025 · The migration file must have been run before (i. Jul 22, 2025 · In this article titled “Laravel 12: How to Rollback a Specific Migration”, I’ll guide you through the process of rolling back a particular migration in a Laravel 12 application — explained Dec 25, 2022 · In Laravel, you can use the migrate:rollback Artisan command to rollback the last migration. e. Dec 25, 2022 · In Laravel, you can use the migrate:rollback Artisan command to rollback the last migration. php I used this command, but it does not remove specific migrations or drop tables from the database in Laravel 9. Oct 18, 2024 · How Laravel migration rollbacks work. To rollback a specific migration, you can pass the --step option to the command, followed by the number of migrations to rollback. 3 onwards, you can just run: php artisan migrate:rollback --step=1 That will rollback the last migration, no matter what its batch number is. May 17, 2015 · I want to rollback only : Rolled back: 2015_05_15_195423_alter_table_web_directories I run php artisan migrate:rollback, 3 of my migration are rolling back. May 21, 2017 · But there is a hacky way to do it in case you really need to. Apr 18, 2024 · Many a time in our life as a Laravel Developer, there comes a situation where you’re in the middle (quite literally) of quite a few migrations that have already been created and migrated when you suddenly need to rollback a specific migration without losing the migrations created after this migration that you want to rollback. This is a powerful way to test and verify changes to a specific table along with fresh test data. Aug 3, 2017 · If you want to just rollback 2016_09_07_103432_create_tabel_roles migration, change it's migration batch value to 2 which is highest among all and then just execute following. This feature is particularly useful during development and testing phases, where I may need to backtrack or fix issues related to database modifications. Rollbacks are particularly useful in environments like local php artisan migrate:rollback --path=database/migrations/2022_07_30_150944_create_posts_table. Also, see run specific migration in laravel 11 and roll Aug 10, 2021 · Then next time you run the rollback command, it’ll only roll back that one migration as it’s in a “batch” of its own. 4 days ago · Laravel infers intent from the migration name when you follow the naming convention, which is why create_posts_table generates a migration with a create schema call and add_column_to_table generates one with an alter call. Rolled back: Jan 5, 2026 · Conclusion Rolling back specific migrations in Laravel requires precision, preparation, and respect for the down() method. You can set the batch value in the migrations table to a higher number than the most recent migration for only the migrations you want to rollback. . Nov 4, 2025 · Learn how to precisely rollback one or multiple Laravel migration files using the --path option for targeted, safe, and efficient database management. A migration rollback in Laravel allows you to reverse the most recent or a specific number of database migrations that have been applied. Sep 29, 2023 · In Laravel, migration rollback allows me to undo specific migrations, reverting the database structure to a previous state. May 1, 2024 · In this guide, we’ll see how to create, run, and roll back migration in laravel 11. Apr 17, 2023 · And you might not want to do that. By using migrate:rollback --path for targeted reverts, verifying migration status with migrate:status, and following safety best practices, you can avoid accidental data loss and keep your database stable. For instance, if you want to rollback the 2014_10_12_100000_create_password_resets_table migration, you can do so like so. With this when you call php artisan migrate:rollback, only that particular migration files with batch value altered would rollback. This feature is particularly handy when you’ve made a mistake in your migrations, or you want to undo a series of migrations for testing purposes. You may roll back a specific "batch" of migrations by providing the batch option to the rollback command, where the batch option corresponds to a batch value within your application's migrations database table. , it should exist in the migrations table), otherwise Laravel won’t be able to rollback it. So, If you only want to rollback a specific migration, you can pass in a --path option to the artisan migrate:refresh command and specify the path to the migration file you want to rollback. hiqfl punydwq ooe inhtv leiouj nktbl nole ybgf zzs nbinm