'laravel and phpunit: could not find driver (SQL: PRAGMA foreign_keys = ON;)
I have run my laravel app with phpunit. Everything is fine until at some point when I run my test again turns out with this error.
Illuminate\Database\QueryException: could not find driver (SQL: PRAGMA foreign_keys = ON;)
Caused by
PDOException: could not find driver
Here's my phpunit.xml file:
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
</php>
OS: Windows 10 | php version: PHP 7.4.11 | sqlite version: SQLite version 3.19.1
Does anyone encounter with this error in laravel 6 and phpunit?
Solution 1:[1]
This is actually happening after I upgraded my php version in laragon. The solution is to enable pdo_sqlite on php extension in laragon. That's it. This answer found here https://laracasts.com/discuss/channels/general-discussion/phpunit-sqlite-error-after-updating-laragon-pdoexception-could-not-find-driver
Solution 2:[2]
If You face this problem
(could not find driver (SQL: PRAGMA foreign_keys = ON;))
You can simply run bellow command on your Ubuntu system
sudo apt-get install php-sqlite3
I think it will help you.. Thanks
Solution 3:[3]
This happens because PDO Sqlite is not enabled. to enable it in Laragon, just open Laragon click on menu > PHP > Extensions > pdo_sqlite That's it.
And if you don't use Laragon the solution might be different. Thanks
Solution 4:[4]
PHP 8.1
sudo apt install php8.1-sqlite3
Note that it needs the 8.1 part!
Solution 5:[5]
Just do the following changes on the php.ini file
extension_dir = "<php installation directory>/php-7.4.3/ext"
extension=php_pdo_sqlite.dll
extension=php_sqlite3.dll
sqlite3.extension_dir = "<php installation directory>/php-7.4.3/ext"
Solution 6:[6]
In case if you have multiple versions of PHP in Laragon you will still see the error. The solution is to enable pdo_sqlite extension on all versions. The reason is that Laragon has its own PHP but Laravel uses the system PHP and you might not know which one is system PHP version.
Solution 7:[7]
For those using windows;
Navigate to the php.ini file(-C:\php\php.ini)
Enable the following:
;extension=pdo_sqlite by removing the /;/ should look like this extension=pdo_sqlite
;extension=sqlite3 should be extension=sqlite3 without the ; symbol
Solution 8:[8]
just enabling these two extension from php.ini file worked for me.
extension=pdo_sqlite
extension=sqlite3
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | totski |
Solution 2 | Eahiya |
Solution 3 | Hasibur Rahman |
Solution 4 | Sliq |
Solution 5 | Saif |
Solution 6 | Nesar Ahmad Nori |
Solution 7 | Emmanuel-Odero |
Solution 8 | Raihan Taher |