php - sqlstate 42s22 column not found 1054 unknown column in 'field list'

标签 php mysql laravel eloquent

伙伴们,我收到错误 sqlstate 42s22 columnactivity_post_commentsnot 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');
    }
}

Database Table

最佳答案

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

ActivityPostComment

在你使用的时候

ActivityPost

关于php - sqlstate 42s22 column not found 1054 unknown column in 'field list',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56336757/

相关文章:

PHP 和 MySQL 在数据库中查找 parent 的所有子孙

mysql - 如果行具有重叠的时间间隔,则对行进行分组

mysql - 用时间查询mysql数据库

php - 帮助处理 PHP Cookie 和一些基本身份验证

c# - 以编程方式查找和替换pdf中的文本

Laravel:从邮件 Blade 模板设置邮件主题

php - 如何使用 AJAX 和 Recaptcha 发送表单? [拉维尔]

Laravel 4.2 错误页面消失了

php - paypal IPN 模拟器在直播时总是给出 INVALID 响应,

php - Zend_Db 和基于日期的查询