【问题标题】:laravel homestead "could not find driver" when using git terminal使用 git 终端时,laravel homestead “找不到驱动程序”
【发布时间】:2018-10-11 16:20:17
【问题描述】:

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

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

但是当我通过 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.

【问题讨论】:

  • 你的本地机器上是否安装了mysql
  • 你检查php -mpdo_mysql 扩展了吗?
  • @Spholt 是的,我确实安装了 Ammps。 ampps.com 它带有 MySQL。我需要卸载这个并重试吗?
  • @mim。 php -m 将 PDO 作为选项之一,所以我猜它已安装!
  • 您能否使用异常中提供的凭据通过命令行连接到您的数据库? (host=192.168.10.10;port=3306;dbname=aff)。你的宅基地箱在运行吗?

标签: php git laravel ssh homestead


【解决方案1】:

当你使用php artisan migrate或seed时,你需要进入宅基地虚拟机终端并运行这些命令,否则它将失败,因为它会找到虚拟机mysql而不是你的windows mysql

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

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

【讨论】:

  • 我将开始这样做 :D 感谢您的支持
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,是因为 /.env 文件中的 db host 错误:

    DB_HOST=127.0.0.1

    将它设置为您的流浪主机(我的 homestead.test):

    DB_HOST=homestead.test

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

    192.168.10.10 homestead.test

    【讨论】:

      【解决方案4】:

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

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

      命令:

      1. vagrant destroy --force
      2. vagrant up

      【讨论】:

        猜你喜欢
        • 2015-04-08
        • 2015-09-06
        • 2021-11-14
        • 2019-01-27
        • 1970-01-01
        • 2020-09-11
        • 2016-05-16
        • 2019-11-07
        相关资源
        最近更新 更多