mercredi 25 juillet 2018

Laravel Delete (Integrity Constraint Violation)

Im trying to implement a delete on my controller but then i have this error

Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (greatsup_wz.entryitems, CONSTRAINT entryitems_fk_check_entry_id FOREIGN KEY (entry_id) REFERENCES entries (id)) (SQL: delete from greatsup_wz.entries where id = 686)


Here is a piece of my code

$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;

How can i fix it ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire