Summer Sale! All accounts are 50% off this week.

Maged's avatar
Level 6

could not find driver issue

when i run phpunit i get this error

Illuminate\Database\QueryException: could not find driver (SQL: PRAGMA foreign_keys = ON;)

i'm working on ubuntu any idea ?

0 likes
11 replies
Tray2's avatar

Are you using MySQL for your tests or SQLite?

Maged's avatar
Level 6

@TRAY2 - sqlite

<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>

i just switched to a new machine so i installed sqlite and everything but still get the same error

Maged's avatar
Level 6

i just reinstalled sqlite and now it's working fine . thnx @Tray2

1 like
Tray2's avatar

Mark the thread as solved by making one of the replies as best answer.

Daniel-Pablo's avatar

Inside PHPUNIT.XML you will find on the bottom some server options check this and change to mysql

        <server name="DB_CONNECTION" value="mysql"/>

that removes the error for me because I am testing with MYSQL NO WITH SQLITE

hope this helps someone else

ekpono's avatar

sudo apt-get install php-sqlite3

FabioPacifici's avatar

For me reinstall sqlite worked fine. The foreign keys are enabled by Laravel in the config/database.php

'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

So, if you get this error today it is likely that the sqlite extension for your php version is not correct.

Try to purge it and reinstall it by running sudo apt-get purge sqlite3 and re-install the extension by running

# run this to check which php.ini file is loaded 
php -i | grep php.ini

You should get an output like:

Configuration File (php.ini) Path => /etc/php/8.0/cli
Loaded Configuration File => /etc/php/8.0/cli/php.ini

From here, given that the php version if 8.0 you can install sqlite extension for it running

sudo apt-get install php8.0-sqlite3
1 like
lincolnbiancardi's avatar

If using mysql, add this line in phpunit.xml:

Then install the mysql package in php $ apt-get install php-mysql

Try again :)

Please or to participate in this conversation.