Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'tokenable_id' cannot be null #75

Closed
rehamwalid opened this issue Feb 18, 2020 · 11 comments
Closed

'tokenable_id' cannot be null #75

rehamwalid opened this issue Feb 18, 2020 · 11 comments

Comments

@rehamwalid
Copy link

I am using airlock for authentication and when i try to create a token it gives me this error

Integrity constraint violation: 1048 Column 'tokenable_id' cannot be null (SQL: insert into personal_access_tokens (name, token, abilities, tokenable_id, tokenable_type, updated_at, created_at) values (admin@email.com, 00f23c417988d8fef36a6275db0a6346acfe6c14004f4bc0d086d9a6249e4e0f, ["*"], ?, Modules\User\Entities\User, 2020-02-18 12:46:10, 2020-02-18 12:46:10))

Any idea why this happen ?

I am using Laravel Framework 6.15.0

@driesvints
Copy link
Member

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

@shopapps
Copy link

shopapps commented Mar 6, 2020

I am experiencing the same issue, could not find anything on the channels you suggested, so have created a new question on stackoverflow:

https://stackoverflow.com/questions/60562572/laravel-airlock-issue-with-creating-tokens-tokenable-id-cannot-be-null

am putting this here just in case others see the same issue and will have somewhere to look.

@qiyu2580
Copy link

$user->save();
$user->createToken('xxx');

@samuelsennev
Copy link

samuelsennev commented Mar 9, 2022

$user->save();
$user->createToken('xxx');

I had the same issue. In my case, I forgot to save the user ($user->save()) before creating his token lol... then, worked.

@Achmad-irfanda
Copy link

i have this same error..
how to fix this problem dude?

@samuelsennev
Copy link

samuelsennev commented May 14, 2022

i have this same error..

how to fix this problem dude?

In my case, I had to save the user before creating his token.

$user->save();

//then
$user->createToken("tokenName");

@iamandreadompe
Copy link

For me the error wars my primary key wasn't id but username,
so i had to set
protected $primaryKey = 'username';

in the model file app/Models/User.php

and everything works well

@mostafa-rami-1
Copy link

For me the error wars my primary key wasn't id but username, so i had to set protected $primaryKey = 'username';

in the model file app/Models/User.php

and everything works well

thanks it thats works for me

@NomanJaved
Copy link

I were also struggling with the same issue

what I were doing wrong was

I have the different table name instead of user -> tw_user

and the problem were I set the user_id as the primary key instead of id. so there were no id column present.

I rename the user_id with the id and it worked for me.

Late answer: but may be help someone else.

@jcfs87
Copy link

jcfs87 commented Jan 16, 2024

i had the same error and worked with
protected $primaryKey = 'users_id';

@mashhoodrehman
Copy link

I had the same problem ,
if you are using selected coulmns , it will through error
Replace this
$user = User::where('email',$loginUserData['email'])
->select('name' , 'email','phone' , 'country_code','password')
->first();
to
$user = User::where('email',$loginUserData['email'])
// ->select('name' , 'email','phone' , 'country_code','password')
->first();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests