Q:

MySQL After Insert Trigger to table with FK to first table

This is my current Trigger:
CREATE DEFINER=`root`@`localhost` TRIGGER `setaccessrole` AFTER INSERT ON `user` FOR EACH ROW BEGIN
    INSERT INTO user_role_linker (user_id, role_id) values (last_insert_id(), 2);
  END

user_role_linker.user_id is FK to user.id, I want an insert into user_role_linker including the last inserted autoincremented ID + user_role = 2, but I get:
#1452 - Cannot add or update a child row: a foreign key constraint fails (`database`.`user_role_linker`, CONSTRAINT `FK_61117899A76ED395` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`))

edit:
I had to use "NEW.id" instead of last_insert_id().
This works.

A:

edit: I had to use "NEW.id" instead of last_insert_id(). This works.

