I have two table of box and box archive for this purpose I write triger which move data from box to box_archived table when user delete box and box archive table data update for this purpose I write following mysql trigger but when I delete box then I receive following error
SQLSTATE[HY000]: General error: 1442 Can't update table 'box' in stored function/trigger because it is already used by statement which invoked this stored function/trigger. (SQL: update `box` set `archive` = 1, `updated_at` = 2018-04-06 07:31:57 where `id` = 48116 and `user_id` = 87)
Below is my trigger code which i write in phpmyadmin MySql
DROP TRIGGER IF EXISTS `move_archived_box`;CREATE DEFINER=`root`@`localhost` TRIGGER `move_archived_box` AFTER UPDATE ON `box` FOR EACH ROW begin
insert into box_archived
select * from box where archive = 1;
delete from box where archive = 1;
end;
I also run trigger only when only archive column is update