未找到列:“字段列表"中的 1054 列“0"未知 - Laravel - 我的代码中的任何地方都没

Column not found: 1054 Unknown column #39;0#39; in #39;field list#39; - Laravel - I don#39;t have a 0 column anywhere in my code(未找到列:“字段列表中的 1054 列“0未知 - Laravel - 我的代码中的任何地方都没有 0 列) - IT屋-程序员软件开发技术分
本文介绍了未找到列:“字段列表"中的 1054 列“0"未知 - Laravel - 我的代码中的任何地方都没有 0 列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我收到这个奇怪的错误:

I'm getting this weird error:

SQLSTATE[42S22]:未找到列:1054 '字段列表'中的未知列 '0'(SQL:更新 forum_threads set 0 = 锁定,1 = 1, updated_at = 2016-03-17 16:01:59 where topic_id = 3 and forum_threads.deleted_at 为空)

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: update forum_threads set 0 = locked, 1 = 1, updated_at = 2016-03-17 16:01:59 where topic_id = 3 and forum_threads.deleted_at is null)

问题是,我没有 0 列.我的代码中的任何地方都没有带有 0 的 where 子句.我正在使用范围查询.

The thing is, I don't have a 0 column. I don't have a where clause with a 0 anywhere in my code. I am using a scope query.

我的控制器是:

    $action = $request->input('action');
    $topic = $request->input('topic');
    $thread = Thread::where('topic_id', $topic);

    switch ($action) {
        case ('locked'):
            $thread->lock();
            break;
    }

如你所见,我做的不多.我只是想锁定一个线程.我在我的 Thread 模型中调用锁作用域.我有很多开关盒,其中之一是lock.我已经在顶部运行了一半的查询,所以我不必重复自己.我只是将它存储在 $thread 变量中,以便我可以执行诸如 $thread->delete()$thread->restore() 之类的操作.

As you can see, I don't do much. I am just trying to lock a thread. I am calling the lock scope in my Thread model. I have a lot of switch cases, one of which is lock. I have run half of the query at the top so I don't have to repeat myself. I simply stored it in the $thread variable so that I can perform actions like $thread->delete() and $thread->restore().

我在线程模型中的查询范围:

My query scope in Thread model:

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

就是这样.我认为这可能是因为我有一个从我的控制器 (Thread::where('topic_id', $topic)) 传递过来的 where 子句,而我只是将它继续到我的范围内.

That's it. I think it may because I have a where clause passing from my controller (Thread::where('topic_id', $topic)) and I'm just continuing it onto my scope.

非常感谢任何帮助.

推荐答案

错误是由于 ->update(['locked', 1]); 应该是 ->update(['locked' => 1]);

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

更新函数使用数组作为列"=>值",你的语法错误导致 Laravel 认为 [ 0 =>'锁定',1 =>1],所以它转换成这个 SQL SET 0 = 'locked', 1 = 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...

这篇关于未找到列:“字段列表"中的 1054 列“0"未知 - Laravel - 我的代码中的任何地方都没有 0 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

In PHP how can you clear a WSDL cache?(在 PHP 中如何清除 WSDL 缓存?)
failed to open stream: HTTP wrapper does not support writeable connections(无法打开流:HTTP 包装器不支持可写连接)
Stop caching for PHP 5.5.3 in MAMP(在 MAMP 中停止缓存 PHP 5.5.3)
Caching HTTP responses when they are dynamically created by PHP(缓存由 PHP 动态创建的 HTTP 响应)
Memcached vs APC which one should I choose?(Memcached 与 APC 我应该选择哪一个?)
What is causing quot;Unable to allocate memory for poolquot; in PHP?(是什么导致“无法为池分配内存?在 PHP 中?)