Column not found: 1054 Unknown column '0' in 'field list' - Laravel - I don't have a 0 column anywhere in my code

后端 未结 4 1571
悲&欢浪女
悲&欢浪女 2021-02-13 11:24

I\'m getting this weird error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column \'0\' in \'field list\' (SQL: update forum_threads set

相关标签:
4条回答
  • 2021-02-13 11:35

    As I mentioned in the comment section, change your function to this:

    public function scopeLock($query)
    {
        return $query->where('locked', 0)->update(['locked' => 1]);
    }
    

    Note the changes in the update method.

    0 讨论(0)
  • 2021-02-13 11:39

    in my case the problem was in the model attributes.I use protected $fillable, protect $foreignKey, protected $timestamp. to solve de problem, I put all the attributes in protect $fillable variable.

    0 讨论(0)
  • 2021-02-13 11:41

    The error is due to ->update(['locked', 1]); which should be ->update(['locked' => 1]);

    the update function uses an array as "column" => "value", your syntax error causes Laravel to think [ 0 => 'locked', 1 => 1], so it translates to this SQL SET 0 = 'locked', 1 = 1...

    0 讨论(0)
  • 2021-02-13 11:47

    I had a double condition in WHERE

    ContestPool::where(['contest_id', '=', $contest_id], ['user_id', '=', $user_id])->delete();
    

    I fixed adding brackets for both conditions

    ContestPool::where([['contest_id', '=', $contest_id], ['user_id', '=', $user_id]])->delete();
    
    0 讨论(0)
提交回复
热议问题