首页 > 解决方案 > 为什么我收到 Laravel php artisan 迁移错误?

问题描述

我是 Laravel 的新手,正在尝试学习在线教程。我到了需要php artisan migrate在终端中运行的地步,但出现以下错误:

  Illuminate\Database\QueryException 

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

  at C:\xampp\htdocs\social\vendor\laravel\framework\src\Illuminate\Database\Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format the error
    666|         // message to include the bindings with SQL, which will make this exception a   
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673| 

  1   C:\xampp\htdocs\social\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDOException::("could not find driver")

  2   C:\xampp\htdocs\social\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=some_db", "root", "", [])

我已经尝试了在这里可以找到的所有解决方案,并且我已经进入我的php.ini文件以启用不同的扩展,但似乎没有任何效果。我找到了一个可以尝试运行的解决方案,sudo apt-get install php-mysql但我使用的是 Windows,所以这不是我的选择。对此事的任何帮助将不胜感激!

标签: phpmysqllaravel

解决方案


如果您已经安装了 mysql 驱动程序,则应确保在 .ENV 文件中分配了以下变量// Si ya tienes el controlador para mysql instalado, debes asegurarte que en el archivo .ENV estén las siguientes variables asignadas:

DB_CONNECTION=mysql //mysql driver
DB_HOST=127.0.0.1   //connection host
DB_PORT=3306        //mysql port
DB_DATABASE=laravel //database name
DB_USERNAME=root    //database user
DB_PASSWORD=        //database password

推荐阅读