[英]Error "Integrity constraint violation" Laravel
我正在从我的项目中删除一家葡萄酒店; 一种葡萄酒与我正在消除的这家葡萄酒商店相关联(关系多对多)。
当我单击删除时,我收到此错误:
SQLSTATE [23000]:完整性约束违规:1451 无法删除或更新父行:外键约束失败( dbfullexercise
,CONSTRAINT wine_wineshop
wineshops
wine_wineshop_wineshop_id_foreign
wineshop_id
id
)
我应该怎么做才能消除这个错误? 我查看了文档,但一无所获。
我是 Laravel 的新手
WineshopController.php
public function destroy(Wineshop $wineshop) { //dd($wineshop); $wineshop->delete(); return redirect(route('wineshop.index')); }
show.blade.php
<form action="{{route('wineshop.destroy', compact('wineshop'))}}" method="post"> @method('delete') @csrf <button type="submit" class="btn btn-danger">Elimina enoteca</button> </form>
网页.php
Route::delete('/wineshop/destroy/{wineshop}', [WineshopController::class, 'destroy'])->name('wineshop.destroy');
使用 SET FOREIGN_KEY_CHECKS 设置父表和子表之间的引用约束:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.