SQLSTATE[42S22]: Column not found: 1054 Unknown column 'provider' in 'field list' (SQL: insert into `oauth_clients`

Viewed 3942

Am using Laravel version 8 and I am trying to run php artisan migrate:refresh --seed & php artisan passport:install

The migrations and seeding successfully run but php artisan passport:install fails

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'provider' in 'field list' (SQL: insert into oauth_clients (user_id, name, secret, provider, redirect, personal_access_client, password_client, revoked, updated_at, created_at) values (?, Laravel Personal Access Client, Wa44O2Z3IA23st3wbgQHvDkapJlS75ZXO7MZ4A4Q, ?, http://localhost, 1, 0, 0, 2021-02-11 15:09:29, 2021-02-11 15:09:29))

Basically while trying to insert the token a column provider is not found and on checking my oauth_clients_table migration file is see that the column provider is actually missing

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

I seem not to find this information about the column, My questions is since this migrations were generated automatically, before I upgraded my application, what is the structure of this column?

EDIT 1 I have tried below and it failed

$table->string('provider');

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'provider' cannot be null (SQL: insert into oauth_clients (user_id, name, secret, provider, redirect, personal_access_client, password_client, revoked, updated_at, created_at) values (?, Laravel Personal Access Client, GiZ5BQgqtbbvCuIupO3bhMZHLK0YlIq22LvjWGGG, ?, http://localhost, 1, 0, 0, 2021-02-11 15:33:28, 2021-02-11 15:33:28))

So I added

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

The above works but now my question is

  1. Is the above correct?
  2. What is the purpose of the provider column in oauth_clients table?
1 Answers

In the Upgrade.md file it mentions:

Upgrading To 9.0 From 8.x

Support For Multiple Guards

PR: https://github.com/laravel/passport/pull/1220

Passport now has support for multiple guard user providers. Because of this change, you must add a provider column to the oauth_clients database table:

Schema::table('oauth_clients', function (Blueprint $table) {
    $table->string('provider')->after('secret')->nullable();
});

If you have not previously published the Passport migrations, you should manually add the provider column to your database.

So I just added the following migration:

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