Search code examples
mysqlsqlmysql-error-1442

Can't update table 'tbl' in stored function/trigger because it is already used by statement which invoked this stored function/trigger


 INSERT INTO `category_sport` (
`id` ,
`category_id` ,
`sport_id` ,
`ordering`
)
VALUES (
NULL , '1', '1', ''
)

what I want to do is manually add few rows to the table for the testing purpose. But when I try to add it gives me below error

#1442 - Can't update table 'tbl' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

table structure

table structure

Trigger

CREATE TRIGGER `update_category_sport_order` AFTER INSERT ON `category_sport`
FOR EACH
ROW UPDATE `category_sport` SET `ordering` = NEW.id WHERE `id` = NEW.id;

How can I add data?


Solution

  • Had to write PHP code manually to fix this.

    http://forums.mysql.com/read.php?99,122354,240978#msg-240978