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 in Devise::Api::TokensController#sign_in #20

Closed dafal closed 1 year ago

dafal commented 1 year ago

👋 I wanted to give a try to this gem but when I try to sign_in I get this error:

ActiveRecord::NotNullViolation in Devise::Api::TokensController#sign_in PG::NotNullViolation: ERROR: null value in column "resource_owner_id" of relation "devise_api_tokens" violates not-null constraint DETAIL: Failing row contains (21, User, null, 8rUvzXixhsNeyypZBWjsm3-aQszFgrBKm2EngYsy1S24PGsYSFrwD6Cxh3Hu, KuxVpFjzq8vopMMzztR3f7i47LgsST33XL44tAzCVA19xCnxZGLztgHwdTDk, 3600, null, null, 2023-04-12 09:50:42.582888, 2023-04-12 09:50:42.582888).

I tried to debug with ChatGPT without success, I can't find where this ressource_owner_id got lost...

vergil-zhao commented 1 year ago

Check issue #11

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

dafal commented 1 year ago

Oups, I did not see this resolved issue. Sorry for this. 😇 Btw what I first tested was to remove the type but it did not work. Forcing it to the default type (biting in my case) solves indeed the issue. Thank you for the help and the great gem !