Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel Can';无法更新记录,因为键入了键_Laravel_Eloquent_Foreign Keys_Schema_Updating - Fatal编程技术网

Laravel Can';无法更新记录,因为键入了键

Laravel Can';无法更新记录,因为键入了键,laravel,eloquent,foreign-keys,schema,updating,Laravel,Eloquent,Foreign Keys,Schema,Updating,我无法更新(而不是删除)记录,因为辅助表中的外键不允许我这样做 我知道我可以禁用外键,但是如果我正在更新“客户”表,我没有考虑好的做法,它没有任何FK到辅助的。 这个问题有什么解决办法吗 我的数据库模式 一个辅助表FK 我得到的错误是什么 这就是我用来做这件事的代码 $customer = Customer::where('id', $id)->update($data); if($customer) return redirect('/customers/);

我无法更新(而不是删除)记录,因为辅助表中的外键不允许我这样做

我知道我可以禁用外键,但是如果我正在更新“客户”表,我没有考虑好的做法,它没有任何FK到辅助的。 这个问题有什么解决办法吗

我的数据库模式

一个辅助表FK

我得到的错误是什么

这就是我用来做这件事的代码

  $customer = Customer::where('id', $id)->update($data);
  if($customer)
      return redirect('/customers/);
多亏了艾伦的帮助


在数组中,我包含了自己记录的ID,因此我将其从数组中取出,更新顺序正在使用活动的foreing键。

添加更新查询或出现此错误时使用的代码。添加了我正在使用的当前代码,如果我禁用了外键,它将起作用,我不希望你成功地使用delete。但无法更新,因为级联方法。更改更新,无以级联。可能有效。您是否正在尝试更新客户的id?您在
$data
中有什么?就是这样!我从数组中取消设置id字段,它正在工作!非常感谢艾伦