Laravel Homestead 使用 Git 终端时"could not find driver"



当我在Windows上使用git终端并尝试运行"PHP Artisan Migrate"来迁移我的表时,我收到此错误:

1 PDOException::("找不到驱动程序"(

但是当我通过 ssh 登录到我的虚拟框"vagrant ssh"时,当我导航到站点文件夹并运行"php artisan migrate"时,它工作得很好。

为什么会发生这种情况?我该如何解决它?

完整的错误消息:

$ php artisan migrate
IlluminateDatabaseQueryException  : could not find driver (SQL: select * fr
om information_schema.tables where table_schema = aff and table_name = migration
s)
at C:UsersjarroDocumentssitesaffvendorlaravelframeworksrcIlluminate
DatabaseConnection.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 th
is exception a
662|         // lot more helpful to the developer instead of just the databa
se's errors.
663|         catch (Exception $e) {
> 664|             throw new QueryException(
665|                 $query, $this->prepareBindings($bindings), $e
666|             );
667|         }
668|
Exception trace:
1   PDOException::("could not find driver")
C:UsersjarroDocumentssitesaffvendorlaravelframeworksrcIlluminate
DatabaseConnectorsConnector.php:68
2   PDO::__construct("mysql:host=192.168.10.10;port=3306;dbname=aff", "homeste
ad", "secret", [])
C:UsersjarroDocumentssitesaffvendorlaravelframeworksrcIlluminate
DatabaseConnectorsConnector.php:68
Please use the argument -v to see more details.

当你使用php artisan migrate或种子时,你需要进入Homestead虚拟机终端并运行这些命令,否则它将失败,因为它会找到虚拟机MySQL而不是你的Windows MySQL

  1. homestead ssh
  2. cd Code/yourapp
  3. php artisan migratephp artisan db:seed

我假设您有像 navicat 或任何可以访问 mysql 虚拟机内部的数据库查看器来跟踪您的命令是否有效。

我发现这工作得更好。虽然你可以在弄乱一段时间后按照温斯顿所说的(标记正确答案(做,但我删除了 Ampps 并下载了 Xampp 并重新安装了作曲家,并将 php exe 路径放在 xampp 上。现在,我可以在本地计算机上执行所有操作,而不是在虚拟机上执行所有操作。

只是以为我会把它放在这里! :D

我遇到了同样的问题,这是因为/.env 文件中的数据库主机错误:

DB_HOST=127.0.0.1

把它设置为你的流浪主机(homestead.test for me(:

DB_HOST=宅基地测试

预计您已将其映射到Windows"主机"文件中:

192.168.10.10 宅基地测试

尝试销毁 Vagrant 虚拟机,然后再次运行 Vagrant。这将重新创建您的流浪者虚拟机

从 Vagrant 文件所在的 Homestead 文件夹中的终端运行这些命令。

命令:

  1. vagrant destroy --force
  2. vagrant up

相关内容

最新更新