Php artisan migrate 没有这样的文件或目录

Php artisan migrate no such file or directory

我在尝试 运行 迁移时创建了一个 make:migration 我收到以下错误

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

在我的 env 文件中,我的数据库名称是 homestead,在我的数据库中,我有一个 table 命名的迁移。不太确定为什么会出现此错误。

1) 运行 命令:

composer dump-autoload

2)回滚命令:

php artisan migrate:rollback

然后创建迁移:

php artisan make:migration create_users_table

以下是对我有用的方法。我正在使用 Homestead vag运行t 盒子,以及一堆其他 Vag运行t 盒子和 Docker 图片用于各种项目,所以我的 Homestead 盒子的 IP 不是 127.0.0.1 ,它是 192.168.10.10。在我将 int .env 文件中的 IP 地址更新为

之前,我得到了 SQLSTATE[HY000] [2002] 的变体
DB_CONNECTION=mysql
DB_HOST=192.168.10.10
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

我的config/database.php

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

我也是运行 php artisan cache:clearphp artisan config:clear 之后的变化。之后运行

php artisan migrate

返回

Migration table created successfully.

希望对大家有所帮助。 您可以在 Homestead/Homestead.yaml 文件中查看您的 Homestead 机器的 IP。

the documentation 中说:

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.

所以使用 vagrant ssh 或者如果您设置了 function in the documentation,请使用 homestead ssh

登录到 vagrant/homstead 虚拟机后,导航到您的代码位置。就我而言,我必须做 cd Code/my-project-name。这取决于您在 Homestead.yaml 文件中设置宅基地的方式。

现在您位于项目文件夹中,运行 php artisan migrate

如果仍然无效,请确保在您的 .env 文件中

我在使用 wsl 时遇到了类似的问题,并通过确保 DB_HOST=localhost 和 mysql 服务在本地 运行 sudo service mysql start[=12 解决了这个问题=]