Laravel Passport 和 PostgreSQL 的连接错误
Connection Error with Laravel Passport and PostgreSQL
我正在使用 POSTGRESQL 数据库安装带有 Laravel Passport 的新 API。安装 Laravel 和基本身份验证时,它工作正常,可以完美地注册用户和登录。 (获取数据库,这很重要!)但是当按照步骤安装 Passport 和 运行 “php artisan migrate” 命令时,Passport 无法识别我正在使用 POSTGRESQL 并寻找连接到 MYSQL,这是不存在的。我会欣赏想法,我不知道还能做什么。
错误:
Illuminate\Database\QueryException
SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (SQL:
create table `oauth_auth_codes` (`id` varchar(100) not null, `user_id` bigint unsigned not
null, `client_id` bigint unsigned not null, `scopes` text null, `revoked` tinyint(1) not
null, `expires_at` datetime null) default character set utf8mb4 collate
'utf8mb4_unicode_ci')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the
error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
我试了没有结果:
php artisan cache:clear
php artisan config:cache
我的.ENV:
#DB_CONNECTION=mysql
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=laravel
#DB_USERNAME=root
#DB_PASSWORD=
我的 CONFIG/DATABASE 与 POSTGRESQL:
'default' => env('DB_CONNECTION', 'pgsql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'xxxx'),
'username' => env('DB_USERNAME', 'xxxxxxxxxxx'),
'password' => env('DB_PASSWORD', 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'someschema',
'sslmode' => 'prefer',
],
我终于在Laravel Passport 论坛找到了解决方案,似乎在最新版本中直接在passport 中配置了与数据库的连接(我不知道为什么它不采取一个来自 .env 或 config / databases),“发布”(导出)来自我将包含 Passport 存储驱动程序的连接文件出售给应用程序,以便能够修改它并声明专用于 Passport 的连接。不用说,Laravel 中有 3 个不同的地方声明与数据库的连接,以直接与 Otwell 聊天为准。
无论如何,这是通过以下命令完成的:
php artisan vendor:publish --tag=passport-config
它在名为 passport.php 的配置文件夹中添加了一个文件,我们在其中找到了准备配置的文件:
/*
|--------------------------------------------------------------------------
| Passport Storage Driver
|--------------------------------------------------------------------------
|
| This configuration options determines the storage driver that will
| be used to store Passport's data. In addition, you may set any
| custom options as needed by the particular driver you choose.
|
*/
'storage' => [
'database' => [
'connection' => env('DB_CONNECTION', 'mysql'),
],
],
我正在使用 POSTGRESQL 数据库安装带有 Laravel Passport 的新 API。安装 Laravel 和基本身份验证时,它工作正常,可以完美地注册用户和登录。 (获取数据库,这很重要!)但是当按照步骤安装 Passport 和 运行 “php artisan migrate” 命令时,Passport 无法识别我正在使用 POSTGRESQL 并寻找连接到 MYSQL,这是不存在的。我会欣赏想法,我不知道还能做什么。
错误:
Illuminate\Database\QueryException
SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (SQL:
create table `oauth_auth_codes` (`id` varchar(100) not null, `user_id` bigint unsigned not
null, `client_id` bigint unsigned not null, `scopes` text null, `revoked` tinyint(1) not
null, `expires_at` datetime null) default character set utf8mb4 collate
'utf8mb4_unicode_ci')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the
error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
我试了没有结果:
php artisan cache:clear
php artisan config:cache
我的.ENV:
#DB_CONNECTION=mysql
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=laravel
#DB_USERNAME=root
#DB_PASSWORD=
我的 CONFIG/DATABASE 与 POSTGRESQL:
'default' => env('DB_CONNECTION', 'pgsql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'xxxx'),
'username' => env('DB_USERNAME', 'xxxxxxxxxxx'),
'password' => env('DB_PASSWORD', 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'someschema',
'sslmode' => 'prefer',
],
我终于在Laravel Passport 论坛找到了解决方案,似乎在最新版本中直接在passport 中配置了与数据库的连接(我不知道为什么它不采取一个来自 .env 或 config / databases),“发布”(导出)来自我将包含 Passport 存储驱动程序的连接文件出售给应用程序,以便能够修改它并声明专用于 Passport 的连接。不用说,Laravel 中有 3 个不同的地方声明与数据库的连接,以直接与 Otwell 聊天为准。
无论如何,这是通过以下命令完成的:
php artisan vendor:publish --tag=passport-config
它在名为 passport.php 的配置文件夹中添加了一个文件,我们在其中找到了准备配置的文件:
/*
|--------------------------------------------------------------------------
| Passport Storage Driver
|--------------------------------------------------------------------------
|
| This configuration options determines the storage driver that will
| be used to store Passport's data. In addition, you may set any
| custom options as needed by the particular driver you choose.
|
*/
'storage' => [
'database' => [
'connection' => env('DB_CONNECTION', 'mysql'),
],
],