laravel homestead "could not find driver" 使用 git 终端时

laravel homestead "could not find driver" when using git terminal

当我在 windows 上使用 git 终端并尝试 运行 "php artisan migrate" 迁移我的表时,我收到此错误:

1 PDOException::("could not find driver")

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

发生这种情况的原因是什么?我该如何解决?

完整的错误信息:

$ php artisan migrate

   Illuminate\Database\QueryException  : could not find driver (SQL: select * fr
om information_schema.tables where table_schema = aff and table_name = migration
s)

  at C:\Users\jarro\Documents\sites\aff\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 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:\Users\jarro\Documents\sites\aff\vendor\laravel\framework\src\Illuminate
\Database\Connectors\Connector.php:68

  2   PDO::__construct("mysql:host=192.168.10.10;port=3306;dbname=aff", "homeste
ad", "secret", [])
      C:\Users\jarro\Documents\sites\aff\vendor\laravel\framework\src\Illuminate
\Database\Connectors\Connector.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 虚拟机内部的数据库查看器来跟踪你的命令是否有效。

我发现这个效果更好。虽然你可以在弄乱它一段时间后按照 Winston 所说的(标记为正确答案)进行操作,但我删除了 Ampps 并下载了 Xampp 并重新安装了作曲家并将 php exe 路径放入 xampp。现在我可以在我的本地机器上而不是在虚拟机上做任何事情。

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

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

DB_HOST=127.0.0.1

将它设置为你的流浪主机(对我来说homestead.test):

DB_HOST=homestead.test

预计您已将其映射到 Windows 'hosts' 文件中:

192.168.10.10 homestead.test

尝试破坏 Vagrant 虚拟机,然后再次 运行 Vagrant。这将重新创建您的 Vagrant 虚拟机

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

命令:

  1. vagrant destroy --force
  2. vagrant up