【问题标题】:Why am I getting a Laravel php artisan migrate error?为什么我收到 Laravel php artisan 迁移错误?
【发布时间】:2020-07-08 15:37:25
【问题描述】:

我是 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,所以这不是我的选择。非常感谢您对此事的任何帮助!

【问题讨论】:

  • 首先你是否已经在 root 上创建了 .env ?你有安装mysql吗?你跑了吗php artisan clear
  • 我有 laravel 包附带的 .env 文件,我有与 phpmyadmin 一起使用的 mysqli。我刚刚跑了php artisan clear,但它并没有解决我的问题。

标签: php mysql laravel


【解决方案1】:

如果您已经安装了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

【讨论】:

  • Tengo esas variables configuradas y el problema sigue ahí
  • "could not find driver" 提示驱动程序没有安装虽然
  • Intenta hacer la conxión desde consola, puede que sea la conectividad con la Base de datos la que falla ¿ En que entorno estás trabajando?编辑:¿Instalaste el driver php-mysql Correcto para tu versión?
  • 这就是我对驱动程序的看法。如果没有,我该如何下载我需要的?
【解决方案2】:

在您的 php.ini 配置文件中,只需取消注释扩展名:

;extension=php_pdo_mysql.dll

(您可以在安装堆栈服务器的 php 文件夹中找到您的 php.ini 文件。)

如果您使用的是 Windows,请输入:extension=php_pdo_mysql.dll

如果您使用的是 Linux,请执行以下操作:extension=pdo_mysql.so

然后快速重启服务器。

如果这对您不起作用,您可能需要将 pdo_mysql 扩展安装到您的 php 库中。

【讨论】:

  • 在运行 php artisan migrate 之前,我已将 DB_DATABASE, DB_USERNAME,DB_PASSWORD 更新为我的个人信息,但我仍然收到错误消息。
  • 您的数据库运行顺畅吗?你能连接到它吗?
  • 您对凭据有 100% 的把握吗?
  • 运行作曲家安装
  • 我已经安装了composer。我对凭据和数据库连接非常肯定。是否有可靠的方法来仔细检查?
猜你喜欢
  • 2014-10-05
  • 2017-06-21
  • 2020-06-28
  • 1970-01-01
  • 2015-08-04
  • 2020-12-13
  • 1970-01-01
  • 2018-10-03
  • 2015-09-21
相关资源
最近更新 更多