gpt4 book ai didi

php - Laravel - 如何创建数据库表

转载 作者:行者123 更新时间:2023-11-29 18:37:49 25 4
gpt4 key购买 nike

我在创建数据库表时遇到问题。

首先我创建模型:

php artisan make:model Company -m

其次,我更新迁移公司文件,添加我需要的列

第三,我将转到 phpMyAdmin 并创建一个名为 test 的新数据库

第四,我运行命令 php artisan migratephp artisan migrate:install ,出现下一个错误:

[Illuminate\Database\QueryException]SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = test and table_name = migrations)

[PDOException]SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

database/config.php中,我将mysql驱动程序编辑为:

'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'test'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'pass'),
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],

.env 文件:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=pass

我还尝试使用 php artisan config:clear 清理缓存。

有人可以帮助我吗?我不明白这是什么问题。

谢谢

最佳答案

在 config/database.php 文件中将密码字段编辑为“password' => env('DB_PASSWORD', ''),并在 .env 文件中 DB_PASSWORD = 将该字段保留为空,如下所示

关于php - Laravel - 如何创建数据库表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45141659/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com