代码之家  ›  专栏  ›  技术社区  ›  Георгий Графов

我有错误“SQLSTATE[42S22]:找不到列:1054“字段列表”中的未知列“0””

  •  0
  • Георгий Графов  · 技术社区  · 2 年前

    当我更新表时,laravel坏了 在另一个网站上,同样的代码运行良好

    
                            $flatBuilder = Lot::where('lotid', $lotid);
                            $arFlat = $flatBuilder->first();
    
                            $arFields[] = array(
                                'lotid' => $lotid,
                                'lot' => $lot,
                                'type' => $type,
                                'status' => $status,
                                'price' => $price,
                                'pricesq' => $pricesq,
                                'area' => $area,
                                'floor' => $floor,
                                'height' => $height
                            );
    
                            if ($arFlat) {
                                $flatBuilder->update($arFields);
                            } else {
                                Lot::create($arFields);
                            }
    

    更新不起作用。。。 我的错误在哪里? 需要帮助!

    1 回复  |  直到 2 年前
        1
  •  0
  •   zlatan    2 年前

    由于您已经将数组值分配给 $arFields ,您不需要将其初始化为空数组。将您的代码更改为此(删除 [] 从$ $ar菲尔兹 )

    $arFields = array(
        'lotid' => $lotid,
        'lot' => $lot,
        'type' => $type,
        'status' => $status,
        'price' => $price,
        'pricesq' => $pricesq,
        'area' => $area,
        'floor' => $floor,
        'height' => $height
    );
    

    结果:

    array:9 [
      "lotid" => 1
      "lot" => 1
      "type" => 1
      "status" => 1
      "price" => 1
      "pricesq" => 1
      "area" => 1
      "floor" => 1
      "height" => 1
    ]
    

    按照你写的方式,你的数组有一个元素,它的值是array:

    array:1 [
      0 => array:9 [
        "lotid" => 1
        "lot" => 1
        "type" => 1
        "status" => 1
        "price" => 1
        "pricesq" => 1
        "area" => 1
        "floor" => 1
        "height" => 1
      ]
    ]
    

    还有 $flatBuilder->update($arFields) 正在使用该元素(在本例中为0)来查找相关列。