SQLSTATE[42S22]:未找到列:1054'字段列表'中的未知列'provider'(SQL:插入到`oauth_clients`
我正在使用 Laravel 版本 8,我正在尝试运行 php artisan migrate:refresh --seed & php artisan passport:install
迁移和播种成功运行但php artisan passport:install失败
SQLSTATE [42S22]:列未找到:1054未知列在'字段列表' '供应商'(SQL:INSERT INTO
oauth_clients(user_id,name,secret,provider,redirect,personal_access_client,password_client,revoked,updated_at,created_at?)值(,Laravel个人访问客户端,Wa44O2Z3IA23st3wbgQHvDkapJlS75ZXO7MZ4A4Q,HTTP ://localhost, 1, 0, 0, 2021-02-11 15:09:29, 2021-02-11 15:09:29))
基本上在尝试插入令牌时provider未找到一列,并且在检查我的 oauth_clients_table 迁移文件时看到该列provider实际上丢失了
public function up()
{
Schema::create('oauth_clients', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id')->nullable()->index();
$table->string('name');
$table->string('secret', 100)->nullable();
$table->text('redirect');
$table->boolean('personal_access_client');
$table->boolean('password_client');
$table->boolean('revoked');
$table->timestamps();
});
}
我似乎没有找到有关该列的此信息,我的问题是由于此迁移是自动生成的,所以在升级我的应用程序之前,该列的结构是什么?
编辑 1
我在下面尝试过,但失败了
$table->string('provider');
SQLSTATE [23000]:完整性约束违规:1048列'供应商'不能为空(SQL:INSERT INTO
oauth_clients(user_id,name,secret,provider,redirect,personal_access_client,password_client,revoked,updated_at,created_at)值(,Laravel个人访问客户端,GiZ5BQgqtbbvCuIupO3bhMZHLK0YlIq22LvjWGGG,HTTP://本地主机, 1, 0, 0, 2021-02-11 15:33:28, 2021-02-11 15:33:28))
所以我加了
$table->string('provider')->nullable('web');
以上工作,但现在我的问题是
- 以上正确吗?
- 表中
provider列的目的是什么oauth_clients?
回答
在 Upgrade.md 文件中,它提到:
从 8.x 升级到 9.0
支持多个守卫
公关:https : //github.com/laravel/passport/pull/1220
Passport 现在支持多个守卫用户提供程序。由于此更改,您必须
provider向oauth_clients
数据库表中添加一列:Schema::table('oauth_clients', function (Blueprint $table) { $table->string('provider')->after('secret')->nullable(); });如果您之前没有发布 Passport 迁移,您应该手动将该
provider列添加到您的数据库中。
所以我只是添加了以下迁移:
<?php
use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
class AddProviderColumnToOauthClientsTable extends Migration
{
public function up()
{
Schema::table('oauth_clients', function (Blueprint $table) {
$table->string('provider')->after('secret')->nullable();
});
}
public function down()
{
Schema::table('oauth_clients', function (Blueprint $table) {
$table->dropColumn('provider');
});
}
}