DEV Community

Cover image for Laravel 12 Rollback a Specific Migration
itstuffsolutions
itstuffsolutions

Posted on

Laravel 12 Rollback a Specific Migration

In this guide, we’ll walk through how to rollback a specific migration in Laravel 12 with clear examples. Sometimes, you don’t want to roll back every migration in your project — you just need to target one particular migration file. Laravel makes this possible, and I’ll show you exactly how.

The methods described here are not limited to Laravel 12; they also work in previous versions like Laravel 7, 8, 9, 10, and 11.

By the end of this tutorial, you’ll know how to:

  • Roll back an individual migration file
  • Roll back and run a specific migration again
  • Roll back a migration and re-seed the database

Why rollback a single migration?

In real-world projects, these scenarios are common:

  • You accidentally created a migration with an error and only need to fix that one.
  • You’re experimenting with one table and don’t want to reset the entire schema.
  • You’re debugging a bug tied to a particular migration or database table.

Instead of using php artisan migrate:rollback (which undoes a whole batch of migrations), you can point Laravel to a specific migration file with the --path option.

⚠️ Important note: When using --path, don’t insert a space after the equal sign. For example:

php artisan migrate:rollback-- path=database/migrations/2025_07_14_134057_create_tests_table.php

Enter fullscreen mode Exit fullscreen mode

If you include a space, Laravel will throw an error.

This way, only the migration at the defined path will be rolled back, leaving the rest of your schema untouched.

Rollback a Specific Migration And Re-Migrate

There are situations where you don’t just want to roll back a migration—you also want to apply it again right away. This is useful when you’ve modified the migration file (for example, fixing a column type or adding a new field) and need to test the updated version.

Laravel makes this easy by allowing you to use the --path option together with the migrate:refresh command. This way, you can target and re-run only the migration you’re working on, without touching the rest of your database schema.

php artisan migrate:refresh --path=databse/migrations/2025_07_14_134057_create_tests_table.php

Enter fullscreen mode Exit fullscreen mode

he command not only rolls back the chosen migration file but also runs it again right away.

This approach is especially handy during development, where you might be making frequent tweaks to a single migration and need to quickly verify the changes—without disturbing the rest of your database structure.

Read Also : Laravel 12 Create, Skip, Run and Rollback Migrations

Rollback a Specific Migration With Seeding

While building a feature, you might need to** reset a specific migration and reload seed data** at the same time. This is particularly helpful when your functionality depends on preloaded data for testing or development.
Laravel makes this possible using the migrate:refresh command together with the --path and --seed options.

Running this will:

  • Roll back the targeted migration
  • Apply the same migration again
  • Execute your database seeders (e.g., DatabaseSeeder or any custom seed classes you’ve defined)

This gives you a clean migration run along with fresh test data, all in one command.

👉 Read the full tutorial on ItStuffSolutions

Top comments (0)