Error trying to insert information into mysql database

1

I have the following tables

Produto {
  idproduto 
  nome
  preco
}
Promocao {
  descricao
  datainicio
  datatermino
  id_produto_fk
}

When trying to insert a new promotion I get the following error:

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails ('mercado_db'.'promocao', CONSTRAINT 'produto_id_fk' FOREIGN KEY ('id_produto_fk') REFERENCES 'produto' ('idproduto') ON DELETE NO ACTION ON UPDATE NO ACTION)
    
asked by anonymous 28.10.2017 / 04:05

1 answer

0

You're trying to enter a promotion for a product that does not exist. Did you already take a look if in your% of promotion%, the value passed to the insert field is a value that exists in the id_produto_fk ??     

28.10.2017 / 04:15