laravel 使用php artisan迁移时出错是Illuminate\Database\QueryException [已关闭]

vltsax25  于 2023-02-20  发布在  PHP
关注(0)|答案(4)|浏览(176)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
昨天关门了。
Improve this question
我想使用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.

我该怎么办?

fnx2tebb

fnx2tebb1#

检查你的.env文件,它应该是这样的.示例

DB_HOST=localhost
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

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

jaxagkaj

jaxagkaj2#

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

php artisan migrate:fresh

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

vfhzx4xs

vfhzx4xs3#

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

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

ztyzrc3y4#

出现这些情况的主要原因是,当输入的MYSql用户名不正确时,您将创建一个新用户,问题将得到解决

相关问题