通过 php artisan 的迁移导致 QueryException

Migration through php artisan results in an QueryException

我已经阅读了很多关于 artisan 迁移问题的帖子,但不幸的是 none 其中适用于我的情况。

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

在我的 Ubuntu 桌面上,我可以通过 DBeaver 连接到数据库,它会显示数据库。因为我 运行 在 Vagrant VM 中连接数据库,所以我通过 192.168.10.10(在 Homestead.yaml 文件中指定)而不是本地主机 (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

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

有人可以给我一些见解吗?

vagrant 中的数据库主机应该是 localhost 或 127.0.0.1,因为项目和数据库都在 vagrant 中,但 DBeaver 在 vm 之外,所以 192.168.10.10 对 DBeaver 没问题。

DB_HOST=localhost

我通过编辑 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.

来解决此问题

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