0
Good people, I have this mistake and I can’t see the solution. I’m working on my first post-college project and I’m in need of some guidance.
I have tables: Client, Ordemdeservico, Budget, Service and Budget.
The Customer, Service Order, Budget and Sevico tables perform all operations as scheduled. The error happens when I try to insert services in the table Orcamentotemservico.
Below I will put an example of the test I did and the error that occurs:
public OrcamentoTemServicoDaoTest() {
}
@Test
public void insetir() {
Cliente c = new Cliente();
c.setCPF("79167357504");
OrdemDeServico ods = new OrdemDeServico();
ods.setNumeroOS(874);
Orcamento o = new Orcamento();
o.setID(1);
Servico s = new Servico();
s.setID(1);
s.setServico("teste");
s.setPrecoVenda(100);
OrcamentoTemServico ots = new OrcamentoTemServico();
ots.setOrcamentoID(o);
ots.setOrdemDeServicoNumeroOS(ods);
ots.setOrdemDeServicoClienteCPF(c);
ots.setQuantidade(1);
ots.setServicoID(s);
ots.setValor(100);
ots.setValorTotal(100);
OrcamentoTemServicoDao otsdao = new OrcamentoTemServicoDao();
otsdao.insert(ots);
}
It says that the test was approved however it presents the error and no information is saved in my table Orcamentotemservico:
Error with.mysql.jdbc.exceptions.jdbc4.Mysqlintegrityconstraintviolationexception: Cannot add or update a Child Row: a Foreign key Constraint fails (gtsassist
.ORCAMENTO_has_SERVICO
, CONSTRAINT fk_ORCAMENTO_has_SERVICO_ORCAMENTO1
FOREIGN KEY (ORCAMENTO_ID
, ORCAMENTO_ORDEM_DE_SERVICO_NUMERO_OS
, `ORCAMENTO_ORDEM_DE_SERVICO_CLIENTE_C)
From now on, thank you very much for the return of the solution.
Did you relate the foreign keys of the table that receives the data to the tables that are in the database ? "the Foreign key Constraint fails ".
– Adaias.Alves
It would be nice to edit the question because Java code is kind of irrelevant, it’s an SQL problem.
– epx