$room = Room::find($id);
$room->bookings()->delete();
$room->delete();
Jan 18, 2021
5
Level 1
Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails
excuse me how can delete i try use of of this method but not successful
1- $room_info = Room::where("id", $id)->delete();
2- DB::table('rooms')->where('id',$id)->delete();
i understand that Rooms have foreign in bookings what best method to delete it with foreign key. thxs
Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (hotelbooking.bookings, CONSTRAINT bookings_room_id_foreign FOREIGN KEY (room_id) REFERENCES rooms (id)) (SQL: delete from rooms where id = 3) in file
Level 61
2 likes
Please or to participate in this conversation.