该列存在,但无法保存

时间:2019-08-30 08:45:07

标签: php sqlite laravel-5 query-builder laravel-5.8

该列存在但无法保存
index.blade.php

<form action="{{route('work.store', ['id' => $param->id])}}" method="post">
@csrf
<input type="hidden" name="project_id" value="{{$param->id}}">

WorkController.php

public function store(Request $request,$id)
{
    $work = new Work;
    $work->fill($request->all())->save();
    return redirect()->route('workindex', ['id' => $id]);
}

create_work_table.php

    Schema::create('work', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->integer('project_id');
        $table->text('content');
        $table->integer('user_id');
        $table->time('work_time');
        $table->string('input_person');
        $table->timestamp('input_date');

        $table->softDeletes();
        $table->timestamps();
    });

web.php

Route::post('/work/{id}', 'WorkController@store')->name('work.store');

存在但不存在

SQLSTATE[HY000]: General error: 1 table category has no column named project_id (SQL: insert into "category" ("project_id", "input_person", "input_date", "user_id", "estimated_work_time", "content", "updated_at", "created_at") values (4, 1, 2019-08-30 08:02:19, 1, 02:00, hoge, 2019-08-30 08:52:15, 2019-08-30 08:52:15))

2 个答案:

答案 0 :(得分:1)

您的表名似乎不正确

SQLSTATE[HY000]: General error: 1 table category has no column named project_id (SQL: insert into "category"

插入类别,但是您已经创建了表名称作品。

答案 1 :(得分:0)

确保您的表具有 project_id

或者确保在您的模型中它应该是可填充的。

protected $fillable = [
        'project_id'
    ];