PHP 7.3.1 Laravel SQLSRV 无法为数据库设置种子

PHP 7.3.1 Laravel SQLSRV failing to seed database

正在尝试使用 laravel php artisan migrate:fresh --seed 为数据库设定种子;但是,它因找不到驱动程序而失败。 驱动程序已安装,应用程序与数据库通信没有问题。

系统信息。

数据库:使用 SQLSRV 驱动程序的 MSSQL

OS: Windows 10

PHP: 7.3.1

阿帕奇 2.4.37

C:\wamp64\www\serialplatesitelaravel\laravel\serialdata> php artisan migrate:fresh --seed  -v

   Illuminate\Database\QueryException  : could not find driver (SQL: EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all";)

  at C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\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 this exception a
    662|         // lot more helpful to the developer instead of just the database'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:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

  2   PDO::__construct("dblib:host=10.172.71.6:1433;dbname=lightcommercial;charset=utf8", "SS****", "SSS****", [])
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

  3   Illuminate\Database\Connectors\Connector::createPdoConnection("dblib:host=10.172.71.6:1433;dbname=lightcommercial;charset=utf8", "SS****", "SS****", [])
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:46

  4   Illuminate\Database\Connectors\Connector::createConnection("dblib:host=10.172.71.6:1433;dbname=lightcommercial;charset=utf8", [])
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Connectors\SqlServerConnector.php:32

  5   Illuminate\Database\Connectors\SqlServerConnector::connect()
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php:182

  6   Illuminate\Database\Connectors\ConnectionFactory::Illuminate\Database\Connectors\{closure}()
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Connection.php:918

  7   call_user_func(Object(Closure))
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Connection.php:918

  8   Illuminate\Database\Connection::getPdo()
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Connection.php:452

  9   Illuminate\Database\Connection::Illuminate\Database\{closure}("EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all";", [])
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Connection.php:657

  10  Illuminate\Database\Connection::runQueryCallback("EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all";", [], Object(Closure))
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Connection.php:624

  11  Illuminate\Database\Connection::run("EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all";", [], Object(Closure))
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Connection.php:459

  12  Illuminate\Database\Connection::statement("EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all";")
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Schema\Builder.php:253

  13  Illuminate\Database\Schema\Builder::disableForeignKeyConstraints()
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Schema\SqlServerBuilder.php:14

  14  Illuminate\Database\Schema\SqlServerBuilder::dropAllTables()
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\FreshCommand.php:73

  15  Illuminate\Database\Console\Migrations\FreshCommand::dropAllTables()
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\FreshCommand.php:46

  16  Illuminate\Database\Console\Migrations\FreshCommand::handle()
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

  17  call_user_func_array([])
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

  18  Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:90

  19  Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Object(Closure))
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:34

  20  Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), [])
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Container\Container.php:580

  21  Illuminate\Container\Container::call()
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Console\Command.php:183

  22  Illuminate\Console\Command::execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\symfony\console\Command\Command.php:255

  23  Symfony\Component\Console\Command\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Console\Command.php:170

  24  Illuminate\Console\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\symfony\console\Application.php:908

  25  Symfony\Component\Console\Application::doRunCommand(Object(Illuminate\Database\Console\Migrations\FreshCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\symfony\console\Application.php:269

  26  Symfony\Component\Console\Application::doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\symfony\console\Application.php:145

  27  Symfony\Component\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Console\Application.php:90

  28  Illuminate\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:122

  29  Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      C:\wamp64\www\serialplatesitelaravel\laravel\serialdata\artisan:37

编辑 1:
证明 SQLSRV 已正确安装。此外,所有从网络对数据库的调用都得到了正确处理。 PHP 环境变量中的 CLI 设置为用于网络的相同 php 文件夹,因此它们应该共享相同的扩展名。

EDIT2:添加了 database.php 片段

'default' => env('DB_CONNECTION', 'sqlsrv'),

/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
 */

'connections' => [

    'sqlsrv' => [
        'driver' => 'sqlsrv',
        'host' => env('DB_HOST', '10.172.71.6'),
        'port' => env('DB_PORT', '1433'),
        'database' => env('DB_DATABASE', 'lightcommercial'),
        'username' => env('DB_USERNAME', 'LCGROUP'),
        'password' => env('DB_PASSWORD', 'LCG4w3b@pp!'),
        'charset' => 'utf8',
        'prefix' => '',
        'prefix_indexes' => true,
    ],

],

WAMP 安装和 Composer 出现问题。 在完全卸载 WAMP 和作曲家以及删除所有相关的环境变量后,错误得到修复。并从头开始重新安装它们。