【问题标题】:SQLSTATE[42S22]: Column not found: 1054 Unknown column ' name' in 'where clause'SQLSTATE [42S22]:未找到列:1054 'where 子句'中的未知列'名称'
【发布时间】:2017-07-08 04:44:41
【问题描述】:

我有一些代码产生以下错误。我该如何解决?

 "SQLSTATE[42S22]: Column not found: 1054 Unknown column ' name' in 'where clause' (SQL: select count(*) as aggregate from `authors` where ` name` = Azzario Razy Junaidi and `id` <> 4)"

AuthorsController.php
public function update(Request $request, $id)
{
    $this->validate($request, ['name' => 'required|unique:authors, name,'.$id]);
    $author = Author::find($id);
    $author->update($request->only('name'));
    Session::flash("flash_notification", [
      "level" => "success",
      "message" => "Berhasil menyimpan $author->name"
    ]);
    return redirect()->route('authors.edit');
}

【问题讨论】:

  • 你使用的是哪个框架??
  • Laravel 框架
  • 名字周围应该有引号为> name = 'Azzario Razy Junaidi' and id 4
  • 密切注意错误。 Unknown column ' name'。为什么你认为这是' name' 而不是'name'?这是一个错字,可能在这里:'required|unique:authors, name,' 但可能在其他地方,未显示。数据库抱怨没有名为[space]name 的列。名称前不能有空格。

标签: php mysql laravel-5


【解决方案1】:

在我看来,您的数据库缺少作者表上的名称列。

"SQLSTATE[42S22]: 列未找到:1054 未知列 'name' in 'where 子句' (SQL: select count(*) as aggregate from authors其中名称 = Azzario Razy Junaidi 和 id 4)

【讨论】:

    【解决方案2】:

    您必须在此处从 AuthorsController.php 中的 (name) 中删除空格:

    'name' => 'required|unique:authors, name,'
    

    然后输入:

    'name' => 'required|unique:authors,name,'
    

    它会起作用?

    【讨论】:

      猜你喜欢
      • 2020-03-01
      • 2020-06-08
      • 1970-01-01
      • 2021-03-29
      • 2023-04-07
      • 2019-08-18
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多