Lädt...

Rollback a Specific Migration in laravel 12

Von itstuffsolutiotions.io vom 2025-07-24 15:58:39<p>In this article titled <strong>&ldquo;Laravel 12: How to Rollback a Specific Migration&rdquo;</strong>, I&rsquo;ll guide you through the process of rolling back a particular migration in a Laravel 12 application &mdash; explained step by step with a practical example. The method shown here is also compatible with earlier Laravel versions including Laravel 7, 8, 9, 10, and 11.</p> <p>In this guide, you&#39;ll discover how to:</p> <p>&nbsp;</p> <ul> <li><strong>Rollback </strong>a specific migration file</li> <li><strong>Re-run </strong>a selected migration after rollback</li> <li>Rollback a specific migration and run database <strong>seeding</strong></li> </ul> <h2>Rollback a Specific Migration</h2> <p>Rather than executing a full<strong> migrate:rollback</strong>&mdash;which reverts the entire last batch of migrations (potentially affecting multiple files)&mdash;Laravel provides a way to <strong>rollback </strong>just one specific migration by using the<strong> --path </strong>option.</p> <pre> <code>php artisan migrate:rollback-- path=database/migrations/2025_07_14_134057_create_tests_table.php</code></pre> <p>🔔<strong> Important:</strong> Ensure there is no space between --path= and the migration file path. Adding a space will result in a command <strong>error</strong>.</p> <h2>Rollback a Specific Migration And Re-Migrate</h2> <p>There are situations where you might need to rollback and instantly re-run a specific migration&mdash;such as after correcting a mistake or updating the table schema.</p> <p>Laravel makes this easy by allowing the use of the <strong>--path</strong> option with the <strong>migrate:refresh</strong> command to target a specific migration file.</p>