8

I created a make:migration when I try to run the migration I get the following error

No such file or directory (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations).

In my env file my db name is homestead and in my db I have a table named migrations. Not really sure why I am getting this error.

Aaron
  • 4,380
  • 19
  • 85
  • 141

4 Answers4

21

Here is what worked for me. I am using Homestead vagrant box, along with a bunch of other Vagrant boxes and Docker images for various projects, so the IP of my Homestead box was not 127.0.0.1, it was 192.168.10.10. I was getting variations of SQLSTATE[HY000] [2002] until I updated the IP address in int .env file to

DB_CONNECTION=mysql
DB_HOST=192.168.10.10
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

and my config/database.php with

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '192.168.10.10'),
        'port' => env('DB_PORT', '3306'),
...

I also ran php artisan cache:clear and php artisan config:clear after the changes. After that running

php artisan migrate

returned

Migration table created successfully.

Hope it helps someone. You can check the IP of your Homestead machine in Homestead/Homestead.yaml file.

  • I have a very similar setup, and this worked for me as well, but I'm not sure why.. It is correct that your (and my) homestead is running on a virtual machine with IP 192.168.10.10, but the mysql server and php are running inside that virtual machine. So for accessing the database from within that virtual machine, you should use localhost, right? Same reason you use port 3306 within the virtual machine and not 33060, which is the port through which you access the DB from your host machine. – Rob Teeuwen Feb 25 '20 at 13:32
  • I was using docker with laradock and had to change .env to DB_HOST=mysql – Memonic May 22 '21 at 21:22
10

1) Run command:

composer dump-autoload

2) rollback command:

php artisan migrate:rollback

Then create your migration:

php artisan make:migration create_users_table

Sunny Doshi
  • 363
  • 2
  • 11
1

In the documentation it says:

If you are using the Homestead virtual machine, you should run this [php artisan migrate] command from within your virtual machine.

Then,

You can SSH into your virtual machine by issuing the vagrant ssh terminal command from your Homestead directory.

So use vagrant ssh or if you set up the function in the documentation, use homestead ssh

Once you are logged into vagrant/homstead virtual machine, navigate to your code location. In my case, I have to do cd Code/my-project-name. This depends on how you have homestead setup in your Homestead.yaml file.

Now that you are in your project folder, run php artisan migrate

If that still doesn't work, make sure in your .env file the DB_PORT is 3306.

zechdc
  • 3,374
  • 9
  • 40
  • 52
0

I had a similar problem using wsl, and solved it by making sure that DB_HOST=localhost and that the mysql service was running locally with sudo service mysql start

Mk-XIII
  • 1
  • 1