0
I can not update the table due to Trigger the goal of it is to store the information of the changed record, so I wanted to know if the problem is in Foreign key(FK), if in that case I would have to create a NEW.id for all FK.
Code of the Trigger:
DROP TRIGGER IF EXISTS trg_update_usuario;
DELIMITER $$
CREATE TRIGGER trg_update_usuario
AFTER UPDATE ON usuario
FOR EACH ROW
BEGIN
INSERT INTO auditoria_usuario(usuario_id_usuario,descricao,data_acao,usuario)
VALUES(NEW.id_usuario,'Alterado',NOW(),USER());
END $$
DELIMITER ;
After the
UPDATE `dpu`.`usuario` SET `nome` = 'Guilherme Roberto'
WHERE (`id_usuario` = '1')
and (`contato_id_contato` = '1')
and (`cargo_id_cargo` = '1')
and (`endereco_id_endereco` = '1');
returns the error:
ERROR 1452: 1452: Cannot add or update a child row: a foreign key
constraint fails (`dpu`.`auditoria_usuario`, CONSTRAINT
`fk_auditoria_usuario_usuario1` FOREIGN KEY (`usuario_id_usuario`,
`usuario_contato_id_contato`, `usuario_cargo_id_cargo`,
`usuario_endereco_id_endereco`))
please show the result of the command
show create table dpu.auditoria_usuario
so that we can analyze.– SpockWayne