【问题标题】:SQLSTATE[42S22]: Column not found: 1054 Unknown column 'provider' in 'field list' (SQL: insert into `oauth_clients`SQLSTATE [42S22]:未找到列:1054“字段列表”中的未知列“提供者”(SQL:插入“oauth_clients”
【发布时间】:2021-02-11 15:27:51
【问题描述】:

我正在使用 Laravel 版本 8,我正在尝试运行 php artisan migrate:refresh --seed & php artisan passport:install

迁移和播种成功运行,但 php artisan passport:install 失败

SQLSTATE[42S22]:找不到列:1054 '字段列表'中的未知列 'provider'(SQL:插入到oauth_clientsuser_idnamesecretprovider,@987654329 @, personal_access_client, password_client, revoked, updated_at, created_at) 值 (?, Laravel Personal Access Client, Wa44O2Z3IA23st3wbgQHvDkapJlS75ZXO7MZ4A4Q, ?, http://localhost, 1, 0, 0, 2, -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 列 'provider' 不能为空 (SQL: 插入 oauth_clients (user_id, name, secret, provider, redirect, @ 987654345@, password_client, revoked, updated_at, created_at) 值 (?, Laravel 个人访问客户端, GiZ5BQgqtbbvCuIupO3bhMZHLK0YlIq22LvjWGGG, ?, http://localhost, 1, 0, 0, 2021-1- :33:28, 2021-02-11 15:33:28))

所以我加了

$table->string('provider')->nullable('web');

以上方法可行,但现在我的问题是

  1. 以上是否正确?
  2. provider 表中oauth_clients 列的用途是什么?

【问题讨论】:

  • 你升级了 laravel 框架还是护照?请查看this线程
  • 谢谢@porloscerrosΨ 这个链接很有帮助

标签: php mysql laravel


【解决方案1】:

在 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 Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

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');
        });
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 2021-10-31
    • 2018-10-23
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多