未找到列:“字段列表"中的 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 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)