【问题标题】:Laravel migration error - could not find driver - Illuminate\Database\QueryExceptionLaravel 迁移错误 - 找不到驱动程序 - Illuminate\Database\QueryException
【发布时间】:2021-12-04 06:04:53
【问题描述】:

我正在尝试按照本教程 https://www.youtube.com/watch?v=074AQVmvvdg&list=PL4cUxeGkcC9hL6aCFKyagrT1RCfVN4w2Q&index=13 进行迁移

我认为本教程可能已过时,因为当我输入 php artisan migrate; 时出现此错误:

 Illuminate\Database\QueryException 

  could not find driver (SQL: select * from information_schema.tables where table_schema = pizzahouse and table_name = migrations and table_type = 'BASE TABLE')

  at C:\Users\jonke\Documents\laravel\pizzahouse\vendor\laravel\framework\src\Illuminate\Database\Connection.php:703        
    699▕         // If an exception occurs when attempting to 
run a query, we'll format the error
    700▕         // message to include the bindings with SQL, 
which will make this exception a
    701▕         // lot more helpful to the developer instead 
of just the database's errors.
    702▕         catch (Exception $e) {
  ➜ 703▕             throw new QueryException(
    704▕                 $query, $this->prepareBindings($bindings), $e
    705▕             );
    706▕         }
    707▕     }

  1   C:\Users\jonke\Documents\laravel\pizzahouse\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDOException::("could not find driver")

  2   C:\Users\jonke\Documents\laravel\pizzahouse\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDO::__construct()

我已阅读视频中的 cmets,在那里我找到了解决早期错误的方法。我在此页面上尝试了以下建议:https://github.com/laravel/framework/issues/24711,这看起来很有希望,但并不快乐。

我在这个网站上发现了描述相同错误消息但原因不同的页面。一个看起来很有希望,但 vscode 不喜欢 sudo apt-get 位。 (我丢失了链接,抱歉)。

这个标题相似但不好用:Migration in Laravel 5.6 - could not find driver

我也尝试过关注官方文档:https://laravel.com/docs/8.x/migrations

如何在 vscode 的命令行中创建数据库但不运行迁移?我不明白!这几天一直在转圈子,有人能帮帮我吗?

谢谢

【问题讨论】:

  • 错误是说你没有安装 pdo_mysql 扩展(如果这是关于 mysql)
  • 是关于MySQL的,听从你的建议,我一直在寻找如何安装pdo_mysql但找不到,请问你有什么建议吗?
  • 在 Windows 上,您通常可以取消注释 php.ini 中的相关行。在某些 linux 发行版中,您可以执行 apt-get install php-pdo-mysql

标签: php laravel visual-studio-code migration


【解决方案1】:

这是c:\php7/php.ini - 需要修改一行 - 取消注释此行:

extension=pdo_mysql

在这里找到答案:https://stackoverflow.com/a/25137901/16714187

【讨论】:

    【解决方案2】:

    添加 JonKemm 解决方案

    这是c:\php7/php.ini - 需要修改一行 - 取消注释此行:extension=pdo_mysql 在这里找到答案:https://stackoverflow.com/a/25137901/16714187

    如果您的问题没有解决任何其他情况,请进一步尝试

    您必须添加驱动程序连接读取代码。您可以在

    中找到
    config->database.php
    

    'mysql' => [
                'driver' => 'mysql',
                'url' => env('DATABASE_URL'),
                'host' => env('DB_HOST', '127.0.0.1'),
                'port' => env('DB_PORT', '3306'),
                'database' => env('DB_DATABASE', 'forge'),
                'username' => env('DB_USERNAME', 'forge'),
                'password' => env('DB_PASSWORD', ''),
                'unix_socket' => env('DB_SOCKET', ''),
                'charset' => 'utf8mb4',
                'collation' => 'utf8mb4_unicode_ci',
                'prefix' => '',
                'prefix_indexes' => true,
                'strict' => true,
                'engine' => null,
                'options' => extension_loaded('pdo_mysql') ? array_filter([
                    PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
                ]) : [],
            ],

    如果你没有在 b/w 中找到这个

    'connections' => [
    ...
    ],
    

    从 Laravel Framework 6.20.30 复制的以上版本

    如果您从旧版 laravel 的这些代码中遗漏了某些内容,请尝试比较或添加一些代码。

    如果你在那里没有找到 mysql 代码 如果您在下面发现任何错误注释,请复制我的代码并粘贴到您的文件中。

    【讨论】:

    • 如果你的问题从我的回答中得到解决,你能批准吗
    • 感谢您的尝试,此代码与我的相同(arrg!)。我试着复制它以防万一,但没有乐趣。
    • 你的问题解决了吗
    • 您是否尝试过使用终端不使用 vscode 进行迁移。
    • App解决了,我把解决方案放在下面。
    猜你喜欢
    • 1970-01-01
    • 2022-06-15
    • 1970-01-01
    • 2020-12-26
    • 2019-12-24
    • 2021-06-10
    • 1970-01-01
    • 2020-10-18
    • 2015-05-20
    相关资源
    最近更新 更多