简体   繁体   中英

Laravel: PHP Artisan Migrate throws PDO Exception: Could not find driver (Postgres)

OS: Ubuntu 16.10

Server: Nginx

DB: PostgreSQL 9.5.4

Laravel 5.4

Trying to perform my database migrations, but php artisan migrate throws the following error:

[Illuminate\Database\QueryException] could not find driver: (SQL select * from information_schema.tables where tables_schema = username and table_name = migrations)

Followed by a second message stating

[PDOException]

could not find driver

I have done the following:

  1. Verified that I have php-pgsql's latest version installed
  2. Uncommented the line pertaining to php_pdo_pgsql.dll in /etc/php/7.0/fpm/php.ini
  3. Restarted both posgtresql and nginx multiple times

Currently, when I run php -i , the output I get for the PDO section is

PDO support => enabled

PDO drivers => pgsql

The pdo_pgsql section yields

PostgreSQL(libpq) Version =>9.5.4

Module version =>7.0.15-0ubuntu0.16.10.4

And the pgsql section returns

PostgreSQL(libpq) Version = 9.5.4

PostgreSQL(libpq) => PostgreSQL 9.5.4 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 6.1.1-11ubuntu12) 6.1.1 20160805, 64-bit Multibyte character support => enabled

SSL support => enabled

Active Persistent Links => 0

Active Links => 0

But in spite of this, still getting the same error. I thought there was some chance it might be a permissions problem, but running the command as either root or www-data has the same result.

you should install PHP pdo

sudo apt upgrade 
sudo apt install php-pgsql

i'v been through the same situation, try the following in order,

1) install the postgre extensions for php, those are:
   php-(YOUR_VERSION)-pgsql, and php-pgsql.
2) enable pgsql extensions in your php.ini file, basically, 
   uncomment the the extensions. 
3) restart the apache server(or nginx).
4) check that extensions are enable using phpinfo() or any else tool.
5) set a password for (in instance) the postgres user in postgreSQL 
   server, this is a very important step.

login to the psql shell:

sudo su - postgres
\password postgres

enter a password and confirm it.

now, set your .env file and try again.

You need to define your .env file

in your.env file you need to specify which database are you using (MySQL, SQLite, Postgres) and specify your DB username and password

APP_ENV=local
APP_KEY=base64:gqaCpjbEfukDr5As7EnrqRzi5PSho1rOS/q2H0E+HOs=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=YOUR_DB_NAME
DB_USERNAME=YOUR_USERNAME
DB_PASSWORD=YOUR_PASSWORD

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

And it is always good to run these commands when working with migrations

composer dump-autoload
php artisan cache:clear
php artisan view:clear

My issue solved by simply installing php-pgsql

I'm using PHP v8.1 So i ran.

sudo apt-get install php8.1-pgsql

Hope this helps.

SOLVED:

Make sure in this scenario that you have run

php artisan cache:clear php artisan config:cache

I thought I'd done this at every pivotal step, but running both of these commands again allowed me to conduct the migration and get the site running properly. Thank you to lewis4u for the assistance, however.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM