来自git clone的Laravel项目无法正常工作(无法使用key:generate或composer install / update)
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.
我正在从github克隆我现有的(并且正常工作的)Laravel项目以启动新项目。 创建一个新副本 .env并从.env.example填充。 然后尝试通常的“作曲家更新(或安装)”和“php artisan key:generate”程序一样。 但是任何与工匠或作曲家的命令最终都会出现此错误:
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>
Try to do migration.
Type in console inside your project dir php artisan migrate
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.