【问题标题】:sqlstate 42s22 column not found 1054 unknown column in 'field list'sqlstate 42s22 列未找到 1054“字段列表”中的未知列
【发布时间】:2019-05-28 07:07:39
【问题描述】:

朋友们,我收到错误sqlstate 42s22 columnactivity_post_cmetsnot found 1054 unknown column in 'field list'

但是这个列名存在于我的数据库中。

我检查了我的数据库并检查了拼写错误,但我仍然收到此错误

public function storecomments(Request $request, $id)
{
    // Create Comment
    $activity_post = new ActivityPost;
    $activity_post->activity_post_comments = $request->input('activity_post_comments');
    $activity_post->activity_post_id = $id;
    $activity_post->user_id = auth()->user()->id;
    $activity_post->save();

    return redirect()->back()->with('success', 'Comment Added');
}

不知道为什么我得到这个错误,所以我不能把这个值保存在我的数据库中

型号:

class ActivityPostComment extends Model
{
	use SoftDeletes;

    // Table Name
    protected $table = 'activity_post_comments';
    // Primary Key
    public $primaryKey = 'id';
    // Timestamps
    public $timestamps = true;

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['deleted_at'];

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

【问题讨论】:

  • 把你的表结构也放上去
  • @GauravGupta 添加
  • 您是否尝试过使用一些默认数据而不是 $request->input('activity_post_cmets');?
  • 你可能还没有在你的模型中定义它,但由于你还没有发布它,我只是猜测
  • @RajveerSingh 您调用错误的模型您的模型类名称是“ActivityPostComment”,而您正在使用“ActivityPost”

标签: php mysql laravel eloquent


【解决方案1】:

根据您发布的上述代码。你调用错误的模型你的模型类名称是

活动发布评论

当你使用时

活动发布

【讨论】:

    猜你喜欢
    • 2019-10-14
    • 2021-10-31
    • 2018-10-23
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多