D
D
Dom Alfro2021-04-30 12:47:50
ORM
Dom Alfro, 2021-04-30 12:47:50

The problem is in eloquent c primary key, why is it not assigned?

Hello ! Please treat the issue appropriately. Perhaps there are "similar" questions on this topic.
But this problem caused me certain difficulties, I can’t solve it for 2 weeks, I didn’t find any resources, solving this problem I collected other errors and now I returned to the same one again.
It’s not clear to me (I googled) whether the primary key (user_id) is automatically set to id when creating a new record (of course, I wrote cascade in migrate ):

->onUpdate('cascade')
            ->onDelete('cascade');)

or it is necessary to write at insert like - $user->user_id = $products->id ? (but I did it anyway ...), I really don’t understand what is the point of doing $user->user_id = $products->id - if as they say in different resources ->onUpdate('cascade') it should automatically add this data when creating a new post.
such a difficulty. I can't understand - should the primary key automatically grab id or should it be assigned when inserting?
I will be grateful for the clarification and maybe links to useful material that I have not yet found myself

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2021-04-30
@JhaoDa

Foreign keys in a database have nothing to do with Eloquent relationships.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question