【问题标题】:Migration through php artisan results in an QueryException通过 php artisan 迁移会导致 QueryException
【发布时间】:2020-06-30 22:33:51
【问题描述】:

我已经阅读了很多关于工匠移民问题的帖子,但不幸的是,这些帖子都不适用于我的情况。

所以我通过 Vagrant 运行 Laravel Homestead,并在 Vagrant VM 中创建了一个新数据库。

在我的 Ubuntu 桌面上,我可以通过 DBeaver 连接到数据库,它会显示数据库。因为我在 Vagrant VM 中运行数据库,所以我通过 192.168.10.10(在 Homestead.yaml 文件中指定)而不是 localhost(127.0.0.1)连接到它。到目前为止一切顺利。

我通过运行以下命令创建了一个迁移文件:php artisan make:migration create_todo_table。但是,当我运行 php artisan migrate 时,出现以下异常错误:

Illuminate\Database\QueryException
Could not find driver (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations and table_type = 'BASE TABLE')

我的.env文件中关于数据库的数据如下:

DB_CONNECTION=mysql
DB_HOST=192.168.10.10
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

我曾尝试通过运行php artisan config:cache 来清除缓存,但没有成功。

有人能给我一些见解吗?

【问题讨论】:

    标签: php mysql laravel vagrant homestead


    【解决方案1】:

    您的 vagrant 中的 DB 主机应该是 localhost 或 127.0.0.1,因为项目和数据库都在 vagrant 内部,但 DBeaver 在 vm 外部,所以192.168.10.10 对于 DBeaver 来说是可以的。

    DB_HOST=localhost

    【讨论】:

      【解决方案2】:

      我通过编辑我的php.ini 文件来解决问题。

      对于 Windows,我将 ;extension=php_pdo_mysql 更改为 extension=php_pdo_mysql.dll

      对于 Ubuntu,我将其更改为 extension=pdo_mysql.so

      在那之后,我仍然收到一条错误消息,指出连接被主动拒绝。我通过将DB_HOST=localhost 更改为DB_HOST=192.168.10.10 来解决此问题。

      希望有一天这会对某人有所帮助!

      【讨论】:

        猜你喜欢
        • 2019-06-30
        • 2020-01-18
        • 2018-06-07
        • 1970-01-01
        • 1970-01-01
        • 2019-11-06
        • 2019-05-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多