来自git clone的Laravel项目无法正常工作(无法使用key:generate或composer install / update)

我正在从github克隆我现有的(并且正常工作的)Laravel项目以启动新项目。
创建一个新副本 .env并从.env.example填充。
然后尝试通常的“作曲家更新(或安装)”和“php artisan key:generate”程序一样。
但是任何与工匠或作曲家的命令最终都会出现此错误:< / p>

  SQLSTATE [HY000] [2002]没有这样的文件或目录(SQL:从settings中选择image_resize,其中id = 1 limit 1)

SQLSTATE [ HY000] [2002]没有这样的文件或目录
</ code> </ pre>

我正在使用MAMP并使用正确且有效的数据库信息填充.env文件(数据库现在为空 )</ p>

 <代码> DB_CONNECTION = MySQL的
DB_HOST =本地主机
DB_PORT = 3306
DB_DATABASE = new_proj_db
DB_USERNAME =根
DB_PASSWORD =根
</代码> </ PRE>

我知道这是一个数据库问题,但我甚至无法使用工厂和种子填充我的数据库虚拟信息。 它们最终都会出现相同的错误“SQLSTATE [HY000] ......”
我无法生成密钥或更新编写器依赖关系。</ p>

也许我应该注释掉一些导致它们的代码 这个问题。 (SQL:从 settings </ code>中选择 image_resize </ code>,其中.....)'image_size'和'settings'是我的代码,但我不明白为什么那些导致问题 一个全新的安装。</ p>

显然我错过了一些非常简单的东西,并对任何建议持开放态度。</ p>
</ div>

展开原文

原文

I'm cloning my existing (and working) Laravel project from github to start a new. Creating a fresh copy of .env and populating from .env.example. Then trying usual "composer update (or install)" and "php artisan key:generate" procedure like always. But any command with artisan or composer ends up with this error:

SQLSTATE[HY000] [2002] No such file or directory (SQL: select `image_resize` from `settings` where `id` = 1 limit 1)

SQLSTATE[HY000] [2002] No such file or directory

I'm using MAMP and have populated .env file with correct and working DB info (Database is empty for now)

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=new_proj_db
DB_USERNAME=root
DB_PASSWORD=root

I'm aware that this is a database problem but i cannot even populate my db with dummy info using factories and seeding. They all end up with the same error "SQLSTATE[HY000]......" I cannot generate key or update composer dependencies.

Maybe i should comment out some code that cause this problem. (SQL: select image_resize from settings where .....) 'image_size' and 'settings' are my code but i cant't understand why those cause a problem on a fresh install.

Apparently i'm missing something really simple and open to any suggestions.

drny20290570
drny20290570 我从你的标题中删除了“已解决”,因为它不是必需的。如果你已经回答了自己的问题,你可以标记为已解答(48小时后):stackoverflow.com/help/self-answer
一年多之前 回复

2个回答



尝试进行迁移。

在项目中的控制台中键入dir php artisan migrate </ code> </ p>
</ div>

展开原文

原文

Try to do migration. Type in console inside your project dir php artisan migrate

dragon202076
dragon202076 就像我说的:=ı不能使用工匠命令。 他们都得到了同样的错误:
一年多之前 回复



我发现了问题。 在register()方法下的'Providers / AppServiceProvider.php'中,我定义了一些使用数据库连接的全局配置。 根据我的理解,每当你提出请求laravel时,首先运行这些函数,因为数据库在项目的最开始就没有准备好会返回错误。
我已注释掉那些行,使用了composer install,key: 像往常一样生成并迁移并播种数据库。 然后重新添加这些行。现在一切正常。</ p>
</ div>

展开原文

原文

I've found the problem. In 'Providers/AppServiceProvider.php' under register() method i had defined some global configurations which use db connections. To my understanding any time you make a request to laravel those functions are run first, because the database is not ready at the very beginning of the project an error is returned. I've commented out those lines, used composer install, key:generate as usual and migrated and seeded the database. Then added those lines back in. Now everything is ok.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐