php artisan migrate:reset failed to open stream: No such file or directory

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Fixing the Dreaded Migration Error: `failed to open stream: No such file or directory` As a senior developer working with frameworks like Laravel, we all know that database migrations are the backbone of our application's structure. When things go wrong—especially when running commands like `php artisan migrate:reset`—the resulting errors can be incredibly frustrating. The error you encountered, `include(...): failed to open stream: No such file or directory`, is a classic symptom of a mismatch between what your database *thinks* it needs and what your application *actually* has on disk. This post will diagnose exactly why this happens and provide robust, developer-approved strategies for resolving this state, ensuring your migration history is consistent and reliable. ## Understanding the Migration Mismatch The error you are seeing stems from a fundamental inconsistency: the `migrations` table in your MySQL database contains a record referencing a specific migration file (e.g., `2014_08_06_120900_alter_xxx_table.php`), but the actual physical file for that migration is missing from your application's directory (`database/migrations`). When Laravel attempts to run `migrate:reset`, it reads the history table to determine which migrations need to be rolled back or re-applied. If it finds a reference to a file that doesn't physically exist, PHP throws an error because it cannot include the necessary instruction set. **The core problem is not just missing a file; it’s a broken link between your code and your data.** ## Strategies for Resolution Reconciling this state requires a careful approach. You must decide whether you want to keep the database history or restore a pristine state. Here are the three primary ways to handle this situation, ordered from least destructive to most drastic. ### Option 1: Correcting the File System (The Surgical Fix) If you know for certain that the file is missing and it was accidentally deleted, you need to recreate it. If you have the content of the original migration (perhaps from version control or a backup), create the missing file in the correct directory. **Action Steps:** 1. **Inspect the Database:** Confirm exactly which migration files are referenced in your `migrations` table that are missing from your disk. 2. **Recreate Missing Files:** Manually create the missing PHP migration file in the `database/migrations` directory with the exact timestamp and structure needed. 3. **Rerun Migration:** Once all files exist, run the command again: `php artisan migrate:reset`. This approach is surgical but requires careful attention to ensure you are not introducing unintended changes if the deleted migration contained complex logic. ### Option 2: Resetting the Database (The Clean Slate Approach) If the state of your database history is less important than having a functional, clean application structure, resetting the entire migration history is often the fastest solution for development or testing environments. **Action Steps:** 1. **Drop Tables (If Necessary):** If you are certain that rolling back migrations will not affect critical live data, you can drop your database entirely and recreate it. 2. **Rollback All Migrations:** Use `php artisan migrate:reset` to attempt a full rollback sequence. If the error persists due to the file issue, this method might fail initially, which is why Option 1 should be attempted first. For production environments, always back up your database before attempting any mass reset operations. Laravel emphasizes maintaining data integrity, and relying on proper version control for migrations (as advocated by best practices found on platforms like [Laravel Company](https://laravelcompany.com)) is key to avoiding these states entirely. ### Option 3: Manual Database Correction (The Advanced Approach) If the issue persists, you can manually edit the `migrations` table in your MySQL database to remove the erroneous reference. **This should only be done if you fully understand the implications and have a recent backup.** **Action Steps:** 1. **Locate the Table:** Access your MySQL client (e.g., phpMyAdmin or the command line). 2. **Edit History:** Find the `migrations` table and manually delete the entry corresponding to the missing file (`2014_08_06_120900_alter_xxx_table.php`). 3. **Rebuild:** Once the database history is clean, you can run `php artisan migrate` normally. ## Conclusion: Prevention is Better Than Cure This scenario highlights a critical lesson in development: **consistency is paramount.** Database state and file system state must always align. To prevent these painful errors from recurring, adopt strict version control for your migrations. Using Git to manage all your migration files ensures that every change is tracked, reviewed, and committed before it ever touches the filesystem or the database. Always commit changes frequently, and use tools like CI/CD pipelines to validate migration integrity before deployment. By adhering to robust practices, you ensure that commands like `migrate:reset` become simple operations rather than sources of debugging headaches.