Sai Harsha
Sai Harsha

Reputation: 321

pdo exception driver not found in laravel for sqlite

When I run php artisan migrate command I get:

[PDOException] could not find driver.

I made my default database as sqlite and checked whether there are pdo drivers for sqlite using php -i command. I could not understand my problem.

Upvotes: 31

Views: 31332

Answers (6)

Igor
Igor

Reputation: 1212

  1. install php extension for sqlite apt --yes install php8.2-sqlite3 (for php 8.2)

  2. go to .env file, set DB_CONNECTION=sqlite and comment another options: DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD and add DB_FOREIGN_KEYS=true

    DB_CONNECTION=sqlite

    #DB_HOST=

    #DB_PORT=

    #DB_DATABASE=

    #DB_DATABASE=

    #DB_USERNAME=

    #DB_PASSWORD=

    DB_FOREIGN_KEYS=true

  3. edit php.ini: find ;extension=pdo_sqlite and remove ; and save file

  4. restart php sudo service php8.2-fpm restart

  5. make permissions for database/database.sqlite as 0777

  6. run php artisan migrate

also do not make changes at config/database.php in sqlite section, it has to be

'database' => env('DB_DATABASE', database_path('database.sqlite')),

Upvotes: 0

pimarc
pimarc

Reputation: 4163

You need to install PDO on your server OR you can just uncomment the following line in your php.ini config file.

To find the php.ini file, you can run php-config to show you where it's located.

Remove the comment character ; from:

;extension=pdo_sqlite

to:

extension=pdo_sqlite

Finally, save the change and restart your server.

Upvotes: 18

askermad
askermad

Reputation: 95

For those using Windows and Xampp Just uncomment theses lines in php.ini :

extension=pdo_sqlite

extension=sqlite3

Upvotes: 6

Jaymin Panchal
Jaymin Panchal

Reputation: 2856

Your system has missing php SQLite installation.

Install it by using:

sudo apt-get install php7.0-sqlite

Then restart your apache server

sudo /opt/lampp/lampp restart

Upvotes: 49

Yusuke Okui
Yusuke Okui

Reputation: 43

I'm using Laravel 5.3 and I had to comment out some params in .env file.

DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=homestead
# DB_USERNAME=homestead
# DB_PASSWORD=secret

Upvotes: -3

Krishan König
Krishan König

Reputation: 482

If you are using sqlite and try to alter a table or drop a column you have to require doctrine/dbal, as suggested in the Laravel docs.

Just do a composer require doctrine/dbal and retry your migration.

Upvotes: 2

Related Questions