我在创建数据库表时遇到问题。
首先我创建模型:
php artisan make:model Company -m
其次,我更新迁移公司文件,添加我需要的列
第三,我将转到 phpMyAdmin
并创建一个名为 test 的新数据库
第四,我运行命令 php artisan migrate
或 php 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/