【问题标题】:why migration databases not working in laravel?为什么迁移数据库在 laravel 中不起作用?
【发布时间】:2019-11-23 08:02:16
【问题描述】:

我是 laravel 的新手,我想先迁移表我更改了 .env 信息(数据库名称、密码、用户名)并制作了模型并编写了属性,但是当我编写命令 php artisan 迁移表时没有出现在我的 phpmyadmin 数据库中并出现以下错误:

SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge' 
(SQL: select * from information_schema.tables where table_schema = forge and 
table_name = migrations and table_type = 'BASE TABLE') catch (Exception $e) {
 > 664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), 
$e 666| ); 667| } ...

【问题讨论】:

  • 什么是错误并添加更多详细信息
  • 请发布错误,以便人们可以帮助您并确保您已连接到您的数据库
  • 这是出现的错误 Illuminate\Database\QueryException : SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge' (SQL: select * from information_schema.tables其中 table_schema = forge and table_name = migrations and table_type = 'BASE TABLE') catch (Exception $e) { > 664| throw new QueryException(665| $query, $this->prepareBindings($bindings), $e 666|); 667| }

标签: php laravel


【解决方案1】:

确保在运行迁移之前创建一个空白数据库

我建议你在你的 sql 中创建新的用户名和密码,然后

上全部授予

然后更新您的 .env 文件与您的数据库用户凭据相同并迁移它。

【讨论】:

    【解决方案2】:

    试试这个:

    1. 作曲家杜。
    2. php artisan make:migration create_model_table.
    3. php 工匠迁移。
      您必须确保输入了正确的数据库凭据。

    【讨论】:

      【解决方案3】:

      确保您在期望项目中运行命令。 您是否通过

      为您的模型创建了迁移文件
      php artisan make:migration create_model_name
      

      更新迁移文件中的列,然后运行

      php artisan migrate
      

      【讨论】:

      • 一旦签入 .env 文件就是数据库用户名和密码。这是正确的吗 ?你是用 xamp 还是 wamp 做服务器
      【解决方案4】:

      如果您通过php artisan serve 运行您的项目,请将其关闭并再次运行。 如果不是,您需要检查您的 mysql 凭据

      【讨论】:

      • 我怎样才能运行它?
      • 只需停止终端或批处理或您在其上运行的任何内容。
      • 如果您使用的是 Windows,请按 ctrl + c
      • 我正在使用 mac 笔记本电脑
      猜你喜欢
      • 2018-06-20
      • 2020-02-20
      • 2016-07-15
      • 2011-10-05
      • 1970-01-01
      • 2017-06-18
      相关资源
      最近更新 更多