'error creating migration in laravel: 'failed to open stream'

I created my first migration create_users_migration using the command:

php artisan make:migration create_users_table

I later on realized there was an error and so deleted the migration file and decided to create different migration file with the same command above. But it keeps throwing this exception:

[ErrorException]
include(/home/awa/Desktop/intern/train2/vendor/composer/../../database/migr
ations/2014_10_12_000000_create_users_table.php): failed to open stream: No
such file or directory

what am I doing wrong?



Solution 1:[1]

I get this error on regular basis, here are some things that might help:

php artisan cache:clear

or delete the cache manually in the bootstrap directory (it is responsible for the route and services cache.

also these methods could help:

composer dump-autoload -o
composer update

Composer dump-autoload regenerates the list of all classes that need to be included in the project (autoload_classmap.php).

the -o / --optimize option converts PSR-4/PSR-0 rules into classmap rules, as a result autoloader doesn't need to access the filesystem, making it run faster - which also is often the source of the problem since Laravel autoloader uses this optimization (caching).

also rolling back the migration has helped to solve the problem several times (if the migration was successful):

php artisan migrate:rollback

Solution 2:[2]

i got this error and i have found a solutions over the community :

php artisan cache:clear

this will delete cached files

composer dump-autoload

composer dump-autoload, will re-generating optimized autoload files for your project agian

php artisan migrate:refresh

then create a new fresh migrate for your database

php artisan make:migration create_users_table --create=users

finally let's start make your new migration file

Solution 3:[3]

You might then need to run composer dump-autoload

Solution 4:[4]

I was getting the same error, tried above solutions - did not work for me. Finally I re-created the deleted migration file using following command.

php artisan make:migration create_my_table

And then I ran following command - now it is working

php artisan migrate:refresh

Solution 5:[5]

Sometime it may be cache issue in Laravel.

No need to install composer and other things.First try simple way:-

Simply add this code in your routes/web.php file

Route::get('/clear-cache', function() {
    Artisan::call('cache:clear');
    return "Cache is cleared";
});

In your browser just hit url

www.yourdomain.com/clear-cache

If it success it will show message

Cache is cleared

Solution 6:[6]

You need to make sure that migrations folder exists inside database folder

Solution 7:[7]

So simple and it works better. Just use:

composer dump-autoload -o

then make your new migration file

Solution 8:[8]

I have updated Laravel to a newer version, and that was the problem. I updated composer and it worked fine. In the project directory run this command:

$ composer update

Solution 9:[9]

The first thing to check is - whether you have a folder created /database/migrations If it doesn't exist, you will get the described error :( Just create it manually and re-run command.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Ro Vinei
Solution 3 Aleksey Boyko
Solution 4 Sunil Sharma
Solution 5 Satish
Solution 6 codigocaballer
Solution 7 Udhav Sarvaiya
Solution 8 Mahsa
Solution 9 Alex K