nejdetkadir / devise-api

The devise-api gem is a convenient way to add authentication to your Ruby on Rails application using the devise gem. It provides support for access tokens and refresh tokens, which allow you to authenticate API requests and keep the user's session active for a longer period of time on the client side
MIT License
152 stars 22 forks source link

ActiveRecord::NotNullViolation (PG::NotNullViolation: ERROR: null value in column "resource_owner_id" of relation "devise_api_tokens" violates not-null constraint #11

Closed rega1237 closed 1 year ago

rega1237 commented 1 year ago

Hello everyone, I have an issue setting up this gem, I follow the instructions and when I try to create a new user I got this error (see the title) the resource_owner_id is null, and if you can see the image attached, when the transaction starts the user is created, I will leave here my model and other things, any help I will really appreciate!

User Model:

Screenshot from 2023-03-27 20-04-58

Schema:

Screenshot from 2023-03-27 20-06-21

image

Error:

Screenshot from 2023-03-27 19-58-27 Screenshot from 2023-03-27 19-58-47

nejdetkadir commented 1 year ago

resource_owner_id field is uuid on your devise_api_tokens table, please change column type as your default primary key type

rega1237 commented 1 year ago

resource_owner_id field is uuid on your devise_api_tokens table, please change column type as your default primary key type

Yeap that works thank you !

chridubois commented 1 year ago

Hi,

i've tried to do what you suggest. I've created a new migration :

class ChangeUuidColumnType < ActiveRecord::Migration[7.0] def change change_column :devise_api_tokens, :resource_owner_id, :primary_key end end

and I get this error :

== 20230529143952 ChangeUuidColumnType: migrating ============================= -- change_column(:devise_api_tokens, :resource_owner_id, :primary_key) rails aborted! StandardError: An error has occurred, this and all later migrations canceled:

PG::SyntaxError: ERROR: syntax error at or near "primary" LINE 1: ..." ALTER COLUMN "resource_owner_id" TYPE bigserial primary ke...

Did I miss something ?