1

Trying to seed the database using laravel php artisan migrate:fresh --seed; however, it fails with a couldn't find driver. Driver's are installed and application communicates with database with no problems.

System information.

Database: MSSQL using SQLSRV Drivers

OS: Windows 10

PHP: 7.3.1

Apache 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

EDIT 1:
Proof that SQLSRV is installed correctly. Also all calls to the database from the web are handled correctly. PHP CLI in environment variables is set to the same php folder used for the web, so they should share same extensions. phpinfo() pdo drivers

EDIT2: Added database.php snippet

'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,
    ],

],
Amr Aly
  • 386
  • 1
  • 14
  • "Driver's are installed" - seems like they're not... Try to connect using [plain php](https://www.php.net/manual/en/ref.pdo-sqlsrv.connection.php) and see what happens – Tarasovych Apr 23 '19 at 06:22
  • Please see edit above – Amr Aly Apr 23 '19 at 14:55
  • `php artisan config:cache`, `php artisan config:clear` - anything helped? – Tarasovych Apr 23 '19 at 15:01
  • Have you tried PHP 7.2 or older version? Same result? – Tarasovych Apr 23 '19 at 15:02
  • Tried php artisan config:cache, php artisan config:clear didn't work. Let me try to downgrade to php 7.2 and see – Amr Aly Apr 23 '19 at 15:44
  • `they should share same extensions` - famous last words. Double check with `php -i` on the CLI. What does your `config/database.php` config look like, is the driver etc correct there? – Don't Panic Apr 23 '19 at 18:14
  • Added database.php to question. `php -i` doesn't show pdo_sqlsrv installed. Also I am able to run the command by adding route `Route::get('/test', function () {Artisan::call('migrate:refresh --seed');});` and visiting /test from the web. So now I am almost certain the problem has to do with php cli, but it seems that wamp has only one php.ini file. – Amr Aly Apr 23 '19 at 18:45
  • Probably cli and fpm are in different directories. – Tarasovych Apr 23 '19 at 21:07
  • Bingo - the problem is exactly what Laravel is telling you, and you've just confirmed by checking the CLI phpinfo - the driver is not installed in your PHP CLI. [This question](https://stackoverflow.com/questions/13827884/php-ini-command-line-php-and-wamp-server-access-different-files) shows how to find your CLI ini file. – Don't Panic Apr 24 '19 at 09:38
  • Okay, very weird. When I run ``php -i | find /i "Configuration File"`` I get ``Configuration File (php.ini) Path => C:\WINDOWS Loaded Configuration File => (none)`` – Amr Aly Apr 25 '19 at 14:39

1 Answers1

0

There was something wrong with the WAMP installation and Composer. The error was fixed after completely uninstalling WAMP & composer as well as deleting all related env vars. And reinstalling them from scratch.

Amr Aly
  • 386
  • 1
  • 14