【问题标题】:error using php artisan migrate is Illuminate\Database\QueryException使用 php artisan migrate 的错误是 Illuminate\Database\QueryException
【发布时间】:2020-04-19 03:53:07
【问题描述】:

我想使用PHP artisan migrate 更新数据库。

首先,我使用了PHP artisan make: auth,它工作正常,但是当我使用migrate 时出现以下错误

C:\memory>php artisan migrate

       Illuminate\Database\QueryException  : SQLSTATE[HY000] [1049] Unknown database 'laravel' (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')

      at C:\memory\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
        660|         // If an exception occurs when attempting to run a query, we'll format the error
        661|         // message to include the bindings with SQL, which will make this exception a
        662|         // lot more helpful to the developer instead of just the database's errors.
        663|         catch (Exception $e) {
      > 664|             throw new QueryException(
        665|                 $query, $this->prepareBindings($bindings), $e
        666|             );
        667|         }
        668|

      Exception trace:

      1   PDOException::("SQLSTATE[HY000] [1049] Unknown database 'laravel'")
          C:\memory\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

      2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=laravel", "root", "", [])
          C:\memory\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

      Please use the argument -v to see more details.

我该怎么办?

【问题讨论】:

    标签: php laravel xampp


    【解决方案1】:

    检查你的 .env 文件,它应该位于 this.Example

    DB_HOST=localhost
    DB_DATABASE=laravel
    DB_USERNAME=root
    DB_PASSWORD=
    

    DB_USERNAMEDB_PASSWORD 对于您的情况可能会有所不同。

    【讨论】:

      【解决方案2】:

      有许多可能的问题可能导致该错误消息,但我认为您只需要在运行迁移时指定这一点:

      php artisan migrate:fresh
      

      如果它不起作用,请检查您的 .env 文件中的数据库连接,确保数据库属性为“laravel”(根据您向我们显示的错误消息)

      【讨论】:

        【解决方案3】:

        执行以下步骤。 配置 .env 文件后运行以下命令

        php artisan config:cache
        php artisan config:clear
        php artisan cache:clear
        

        【讨论】:

          【解决方案4】:

          这些情况的主要原因是当MYSql用户名输入错误你会创建一个新用户然后问题就会解决

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2020-01-20
            • 2021-12-11
            • 2021-01-05
            • 2018-12-17
            • 2020-08-16
            • 2018-11-12
            • 2017-09-28
            • 1970-01-01
            相关资源
            最近更新 更多