PDOException:找不到驱动程序但启用了 SQLite3
Posted
技术标签:
【中文标题】PDOException:找不到驱动程序但启用了 SQLite3【英文标题】:PDOException: could not find driver but SQLite3 enabled 【发布时间】:2020-03-10 09:40:57 【问题描述】:我正在尝试在使用 SQLite 作为测试数据库的 nginx-Alpine docker 映像中运行 phpUnit 测试
我安装了 sqlite3 扩展,这是 php -r "phpinfo();"
的输出
但是,当我运行测试时仍然得到这个错误
Tests\Feature\CardTypeTest::testCardTypeCreation
Illuminate\Database\QueryException: could not find driver (SQL: PRAGMA writable_schema = 1;)
/var/www/vendor/illuminate/database/Connection.php:664
/var/www/vendor/illuminate/database/Connection.php:624
/var/www/vendor/illuminate/database/Connection.php:333
/var/www/vendor/illuminate/database/Schema/SQLiteBuilder.php:18
/var/www/vendor/illuminate/database/Console/Migrations/FreshCommand.php:79
/var/www/vendor/illuminate/database/Console/Migrations/FreshCommand.php:46
/var/www/vendor/illuminate/container/BoundMethod.php:32
/var/www/vendor/illuminate/container/BoundMethod.php:90
/var/www/vendor/illuminate/container/BoundMethod.php:34
/var/www/vendor/illuminate/container/Container.php:576
/var/www/vendor/illuminate/console/Command.php:183
/var/www/vendor/symfony/console/Command/Command.php:255
/var/www/vendor/illuminate/console/Command.php:170
/var/www/vendor/symfony/console/Application.php:934
/var/www/vendor/symfony/console/Application.php:273
/var/www/vendor/symfony/console/Application.php:149
/var/www/vendor/illuminate/console/Application.php:90
/var/www/vendor/illuminate/console/Application.php:182
/var/www/vendor/laravel/lumen-framework/src/Console/Kernel.php:165
/var/www/vendor/laravel/lumen-framework/src/Testing/TestCase.php:315
/var/www/vendor/laravel/lumen-framework/src/Testing/DatabaseMigrations.php:14
/var/www/vendor/laravel/lumen-framework/src/Testing/TestCase.php:89
/var/www/vendor/laravel/lumen-framework/src/Testing/TestCase.php:76
/var/www/tests/Feature/CardTypeTest.php:21
Caused by
PDOException: could not find driver
/var/www/vendor/illuminate/database/Connectors/Connector.php:70
/var/www/vendor/illuminate/database/Connectors/Connector.php:46
/var/www/vendor/illuminate/database/Connectors/SQLiteConnector.php:25
/var/www/vendor/illuminate/database/Connectors/ConnectionFactory.php:218
/var/www/vendor/illuminate/database/Connection.php:919
/var/www/vendor/illuminate/database/Connection.php:944
/var/www/vendor/illuminate/database/Connection.php:399
/var/www/vendor/illuminate/database/Connection.php:325
/var/www/vendor/illuminate/database/Connection.php:657
/var/www/vendor/illuminate/database/Connection.php:624
/var/www/vendor/illuminate/database/Connection.php:333
/var/www/vendor/illuminate/database/Schema/SQLiteBuilder.php:18
/var/www/vendor/illuminate/database/Console/Migrations/FreshCommand.php:79
/var/www/vendor/illuminate/database/Console/Migrations/FreshCommand.php:46
/var/www/vendor/illuminate/container/BoundMethod.php:32
/var/www/vendor/illuminate/container/BoundMethod.php:90
/var/www/vendor/illuminate/container/BoundMethod.php:34
/var/www/vendor/illuminate/container/Container.php:576
/var/www/vendor/illuminate/console/Command.php:183
/var/www/vendor/symfony/console/Command/Command.php:255
/var/www/vendor/illuminate/console/Command.php:170
/var/www/vendor/symfony/console/Application.php:934
/var/www/vendor/symfony/console/Application.php:273
/var/www/vendor/symfony/console/Application.php:149
/var/www/vendor/illuminate/console/Application.php:90
/var/www/vendor/illuminate/console/Application.php:182
/var/www/vendor/laravel/lumen-framework/src/Console/Kernel.php:165
/var/www/vendor/laravel/lumen-framework/src/Testing/TestCase.php:315
/var/www/vendor/laravel/lumen-framework/src/Testing/DatabaseMigrations.php:14
/var/www/vendor/laravel/lumen-framework/src/Testing/TestCase.php:89
/var/www/vendor/laravel/lumen-framework/src/Testing/TestCase.php:76
/var/www/tests/Feature/CardTypeTest.php:21
【问题讨论】:
请分享您的数据库配置文件。 (通常是 config/database.php) @a_sarana 或者你的意思是 phpunit.xml 配置?这应该是它在测试期间使用的。 【参考方案1】:终于观察到php-pdo_sqlite
扩展丢失了。
使用apk add --update php-pdo_sqlite
安装它,现在工作正常。
【讨论】:
以上是关于PDOException:找不到驱动程序但启用了 SQLite3的主要内容,如果未能解决你的问题,请参考以下文章