我试图在控制器上实现删除,但出现以下错误:
完整性约束冲突:1451无法删除或更新父行:外键约束失败 (
greatsup_wz.
entryitems, CONSTRAINT
entryitems_fk_check_entry_idFOREIGN KEY (
entry_id) REFERENCES
entries(
id)) (SQL: delete from
greatsup_wz.
entrieswhere
id= 686)
下面是我的一段代码:
$entryTable = DB::table(config("app.DB_ACCOUNTING").".entryitems")
->where('entryref_id','=',100)->get();
foreach($entryTable as $entryTbl):
DB::table(config("app.DB_ACCOUNTING").".entries")
->where('id','=',$entryTbl->entry_id)->delete(); // this is where my error occurred
endforeach;
我该怎么修?
1条答案
按热度按时间y3bcpkx11#
您添加的约束将阻止删除数据。您需要更新数据库架构。您需要在entryitems迁移中添加ondelete('cascade')