laravel Php artisan 迁移没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43686135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:52:45  来源:igfitidea点击:

Php artisan migrate no such file or directory

laravelmigrate

提问by Aaron

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

我创建了一个 make:migration 当我尝试运行迁移时出现以下错误

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

没有这样的文件或目录(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.

在我的 env 文件中,我的数据库名称是 homestead,在我的数据库中,我有一个名为 migrations 的表。不确定为什么我会收到此错误。

回答by Maxim Safioulline

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

这对我有用。我正在使用 Homestead vagrant box,以及一堆其他 Vagrant box 和用于各种项目的 Docker 镜像,所以我的 Homestead box 的 IP 不是 127.0.0.1,而是 192.168.10.10。我得到的变化SQLSTATE[HY000] [2002],直到我更新INT .ENV文件中的IP地址

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.phpwith

和我config/database.php

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

I also ran php artisan cache:clearand php artisan config:clearafter the changes. After that running

我也跑了php artisan cache:clearphp artisan config:clear在改变之后。在那之后运行

php artisan migrate

returned

回来

Migration table created successfully.

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

希望它可以帮助某人。您可以在Homestead/Homestead.yaml文件中检查您的 Homestead 机器的 IP 。

回答by Sunny Doshi

1) Run command:

1)运行命令:

composer dump-autoload

作曲家转储自动加载

2) rollback command:

2)回滚命令:

php artisan migrate:rollback

php工匠迁移:回滚

Then create your migration:

然后创建您的迁移:

php artisan make:migration create_users_table

php artisan make:migration create_users_table

回答by zechdc

In the documentationit says:

文档中它说:

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

如果你使用的是 Homestead 虚拟机,你应该在你的虚拟机中运行这个 [php artisan migrate] 命令。

Then,

然后

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

您可以通过vagrant ssh从 Homestead 目录发出终端命令来通过 SSH 连接到您的虚拟机。

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

所以使用vagrant ssh或者如果您在文档中设置函数,请使用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.

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

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

现在你在你的项目文件夹中,运行 php artisan migrate

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

如果这仍然不起作用,请确保在您的.env文件中DB_PORT 是3306.