Laravel执行迁移报错:could not find driver(SQLite连接)求助
Laravel 初始化时 SQLite 驱动缺失报错
错误详情
处理post-create-project-cmd事件的脚本
@php artisan migrate --ansi返回错误码1
具体错误栈:
Illuminate\Database\QueryException 找不到驱动程序(连接:sqlite,SQL:PRAGMA foreign_keys = ON;) at vendor\laravel\framework\src\Illuminate\Database\Connection.php:813 809▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 810▕ ); 811▕ } 812▕ ➜ 813▕ throw new QueryException( 814▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 815▕ ); 816▕ } 817▕ } 1 vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:65 PDOException::("could not find driver") 2 vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:65 PDO::__construct()
问题原因
PHP环境未安装SQLite的PDO驱动,导致Laravel执行数据库迁移时无法连接SQLite数据库。
解决步骤
1. 检查驱动状态
执行命令确认pdo_sqlite扩展是否存在:
php -m | grep pdo_sqlite
无输出则说明该扩展未安装。
2. 安装SQLite PDO驱动
根据操作系统选择对应操作:
Windows系统
- 打开PHP配置文件
php.ini - 找到
extension=pdo_sqlite,去掉行首的分号; - 重启Web服务器(Apache/Nginx)或PHP-FPM
Debian/Ubuntu系统
sudo apt-get install php-sqlite3 sudo systemctl restart php-fpm # 若使用Apache则执行:sudo systemctl restart apache2
CentOS/RHEL系统
sudo yum install php-sqlite3 sudo systemctl restart php-fpm sudo systemctl restart httpd
3. 验证并重试
再次执行php -m | grep pdo_sqlite,输出pdo_sqlite即为安装成功,然后重新运行迁移:
php artisan migrate
内容的提问来源于stack exchange,提问作者Vasekvlachyseznamcz Vasek
相关产品推荐
相关产品推荐

