Remove specific migration in laravel
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
How to Safely Remove a Specific Migration in Laravel: A Developer's Guide
As a senior developer working with Laravel, you often encounter situations where you need to clean up your migration history. The documentation rightly points out that commands like migrate:rollback and migrate:reset are excellent for managing batch operations or resetting the entire database state, but they fall short when the goal is to surgically remove a single, specific migration file and its corresponding database changes.
The core challenge here is that Laravel manages migration history through the migrations table in your database. Deleting a migration file directly from your filesystem does not automatically update this tracking table, leading to potential inconsistencies if you are not careful.
This post will explore the limitations of standard commands and provide a thorough, practical strategy for safely removing a specific migration, keeping data integrity as our top priority.
Understanding Laravel Migration History
When you run php artisan migrate, Laravel records every executed migration in the migrations table. This table serves as the single source of truth for what has been applied to your database. Any attempt to bypass this mechanism manually risks creating a state where your application code (the migration files) no longer matches the actual state of the database, which is a recipe for deployment errors or data corruption.
Standard rollback commands, such as php artisan migrate:rollback, only reverse the last N migrations executed. They do not offer a direct mechanism to target and delete an arbitrary file from history.
The Strategy: Manual Deletion and Reversion
Since Laravel does not provide a single command for deleting an arbitrary migration, we must execute a multi-step process that prioritizes safety and data integrity. It is crucial to understand that this process requires manual intervention and should never be performed on production databases without a full backup.
Here is the safest sequence of steps:
Step 1: Backup Your Database
Before making any structural changes, always create a complete backup of your database. This is non-negotiable, especially when dealing with schema changes.
Step 2: Reverse the Migration (If Possible)
If the migration you wish to remove was recent and its changes are reversible (i.e., it only added columns or tables), use the rollback command to revert those specific changes first.
php artisan migrate:rollback --step=1 # Example: Rolls back the last batch
Step 3: Manually Delete the Migration File
Once you have ensured the database state is consistent with your desired outcome, you can safely delete the migration file from your project directory and your version control system (Git).
For example, if you want to remove 2023_10_26_add_old_feature.php, simply delete that file:rm /path/to/migrations/2023_10_26_add_old_feature.php
Step 4: Update the Database History (Advanced)
This is the most delicate step. If you have successfully removed the file from your local history, you must now update the migrations table in your database to reflect this change. This usually involves manually deleting the corresponding entry from the migrations table for that specific migration name.
Warning: Directly manipulating the migrations table is an advanced operation. If you are working with complex migrations or production data, consulting the official Laravel documentation regarding database structure is vital. For general architectural guidance on building robust systems, understanding framework conventions mirrors the principles discussed at resources like Laravel Company.
Best Practice: Handling History in Development vs. Production
For development environments, where you have full control and can easily recreate the environment, manually deleting files and adjusting the history table is acceptable for cleanup.
However, for production deployments, manual surgery on migration history is strongly discouraged. The recommended practice in a professional setting, as emphasized by Laravel best practices, is to treat migration history as immutable. Instead of deleting a migration, the preferred approach is:
- Create a New Migration: Write a new migration that correctly implements the desired final state of your schema.
- Roll Forward: Run
php artisan migrate.
This method ensures that the history remains intact, providing an auditable trail for every change, which is essential for debugging and collaboration, aligning with the principles of maintainability discussed in Laravel documentation.
Conclusion
In summary, while Laravel does not offer a single command to "delete" a specific migration file, you can achieve the desired result through careful, multi-step manual intervention: reverting database changes, deleting the physical file, and manually cleaning up the migrations table entry. Always prioritize data safety and version control when performing these operations. For robust application development, embracing a history-preserving approach is always the superior architectural choice over attempting to surgically erase history.