K
K
KRAcoder2020-12-27 02:57:01
Laravel
KRAcoder, 2020-12-27 02:57:01

Why does Laravel get the error Column not found: 1054 Unknown column 'id' when using the save() method?

public function subTaskReductedSentKind1($sub_id, Request $request ){
            session(['definitions'=>$request->input('definitions')]);
            session(['words'=>$request->input('words')]);
            session(['correct_words'=>$request->input('correct_words')]);

            $sub_task = Task_1st_kind::where('sub_task', $sub_id)->first();

            $sub_task->definitions = session()->get('definitions');
            $sub_task->words = session()->get('words');
            $sub_task->correct_words = session()->get('correct_words');

            $sub_task->save();

            return redirect()->route('Admin');
    }

The id column is not mentioned anywhere.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2020-12-27
@KRAcoder

It's most likely under the hood.

$sub_task = Task_1st_kind::where('sub_task', $sub_id)->first();

Because it pulls out an object with all fields.
Reasons:
1) there is no id column in the database
2) id is not the primary key in the table
3) the table has a non-standard primary key, this must be specified in the model class

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question