简体   繁体   中英

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'session' in 'field list' in Laravel

I am getting a strange error! I did not create any field named 'session' in database and there is no such field in model named 'session'. I used SoftDeletes() in the model but whenever I am trying to insert data I get an error with this message:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'session' in 'field list'

Here is the model:

<?php 

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

use Illuminate\Database\Eloquent\SoftDeletes;

class Article extends Model
{
use SoftDeletes;

protected $fillable = [
    'user_id', 'headline', 'summary', 'body', 'status', 'cover_image', 'image_caption', 'image_credit', 'cover_video', 'video_caption', 'video_credit', 'category', 'meta', 'tags',
]; 

protected $dates = ['deleted_at'];

public function user()
{
    return $this->belongsTo('App\User');
}

}

Here is the database: enter image description here

Here is the controller:

public function store(Request $request)
{
    $article = new Article;
    $article->user_id = $request->user_id;   
    $article->headline = $request->headline;  
    $article->summary = $request->summary;   
    $article->body = $request->body;   
    $article->status = $request->status;   
    $article->session = $request->session;
    $article->category = $request->category;
    $article->meta = $request->meta;
    $article->tags = $request->tags;


    //dd($request->session());


    $article->save();

    return back()->with('success', 'Article Successfully Added!');
}

How can I solve this problem?

我认为您不应该将$request->session放在$article->session尤其是如果您通过雄辩的->save()保存它,请点击此处了解有关Laravel Eloquent的更多信息: https ://laravel.com/docs/5.7/eloquent #插入和更新管理模式

hi because in your store function you do this

 $article->session = $request->session;

delete this and it s work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM