{"id":1325,"date":"2023-11-30T05:40:30","date_gmt":"2023-11-30T05:40:30","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=1325"},"modified":"2023-11-30T05:40:31","modified_gmt":"2023-11-30T05:40:31","slug":"resolving-sqlstate42s22-error-in-laravel-passport-upgrade","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/resolving-sqlstate42s22-error-in-laravel-passport-upgrade\/","title":{"rendered":"Resolving SQLSTATE[42S22] Error in Laravel Passport Upgrade"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"261\" src=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-41-1024x261.png\" alt=\"\" class=\"wp-image-1326\" srcset=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-41-1024x261.png 1024w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-41-300x76.png 300w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-41-768x195.png 768w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-41-850x216.png 850w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-41.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Laravel Passport, a powerful OAuth2 server for Laravel, is widely used to authenticate users and authorize access to APIs. However, upgrading from an older version of Laravel to a newer one, as in the case of upgrading from Laravel 5.7 to 10.10, can introduce compatibility issues. One such issue is the SQLSTATE[42S22] error, specifically related to the &#8220;unknown column &#8216;provider&#8217; in &#8216;field list'&#8221; in the <code>oauth_clients<\/code> table.<\/p>\n\n\n\n<p>Solution: To resolve the SQLSTATE[42S22] error and address the missing &#8216;provider&#8217; column, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Update Database Schema:<\/strong> Laravel Passport now supports multiple guard user providers, requiring the addition of a &#8216;provider&#8217; column to the <code>oauth_clients<\/code> table. Use the following Laravel migration snippet to add the &#8216;provider&#8217; column:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>use Illuminate\\Database\\Migrations\\Migration;\r\nuse Illuminate\\Database\\Schema\\Blueprint;\r\nuse Illuminate\\Support\\Facades\\Schema;\r\n\r\nclass AddProviderToOauthClientsTable extends Migration\r\n{\r\n    public function up()\r\n    {\r\n        Schema::table('oauth_clients', function (Blueprint $table) {\r\n            $table->string('provider')->after('secret')->nullable();\r\n        });\r\n    }\r\n\r\n    public function down()\r\n    {\r\n        Schema::table('oauth_clients', function (Blueprint $table) {\r\n            $table->dropColumn('provider');\r\n        });\r\n    }\r\n}\r\n<\/code><\/pre>\n\n\n\n<p>Run the migration using the following Artisan command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan migrate\r\n<\/code><\/pre>\n\n\n\n<p>This adds the &#8216;provider&#8217; column to the <code>oauth_clients<\/code> table.<\/p>\n\n\n\n<p><strong>Manually Update Database (if necessary):<\/strong> If you haven&#8217;t published the Passport migrations before, you might need to manually add the &#8216;provider&#8217; column to your database table. Execute the appropriate SQL query to alter the <code>oauth_clients<\/code> table:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER TABLE oauth_clients ADD COLUMN provider VARCHAR(255) AFTER secret;\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Laravel Passport, a powerful OAuth2 server for Laravel, is widely used to authenticate users and authorize access to APIs. However, upgrading from an older version of Laravel&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[562,566,565,564,563,561,567],"class_list":["post-1325","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-error-in-laravel-passport-upgrade","tag-laravel-migration","tag-migration","tag-oauth_clients","tag-provider","tag-resolving-sqlstate42s22-error-in-laravel-passport-upgrade","tag-sql"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=1325"}],"version-history":[{"count":1,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1325\/revisions"}],"predecessor-version":[{"id":1327,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1325\/revisions\/1327"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=1325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=1325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=1325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}