Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Erro ao popular tabela Fato_001

Estou enfrentando um erro no processo de popular a tabela fato_001, segui os passos do aula fazendo um Table Input com dados do SQL Server, e dando um Inser/Update no MySQL. Ao executar o processo recebo a seguinte mensagem de erro.

2021/06/14 11:58:00 - Insert / update.0 - ERROR (version 9.1.0.0-324, build 9.1.0.0-324 from 2020-09-07 05.09.05 by buildguy) : Error in step, asking everyone to stop because of:
2021/06/14 11:58:00 - Insert / update.0 - ERROR (version 9.1.0.0-324, build 9.1.0.0-324 from 2020-09-07 05.09.05 by buildguy) : org.pentaho.di.core.exception.KettleDatabaseException: 
2021/06/14 11:58:00 - Insert / update.0 - Error inserting/updating row
2021/06/14 11:58:00 - Insert / update.0 - Cannot add or update a child row: a foreign key constraint fails (`dwsucos`.`fato_001`, CONSTRAINT `dim_produto_fato_001_fk` FOREIGN KEY (`Cod_Produto`) REFERENCES `dim_produto` (`Cod_Produto`) ON DELETE NO ACTION ON UPDATE NO ACTION)
2021/06/14 11:58:00 - Insert / update.0 - 
2021/06/14 11:58:00 - Insert / update.0 -     at org.pentaho.di.core.database.Database.insertRow(Database.java:1331)
2021/06/14 11:58:00 - Insert / update.0 -     at org.pentaho.di.core.database.Database.insertRow(Database.java:1255)
2021/06/14 11:58:00 - Insert / update.0 -     at org.pentaho.di.core.database.Database.insertRow(Database.java:1243)
2021/06/14 11:58:00 - Insert / update.0 -     at org.pentaho.di.core.database.Database.insertRow(Database.java:1231)
2021/06/14 11:58:00 - Insert / update.0 -     at org.pentaho.di.trans.steps.insertupdate.InsertUpdate.lookupValues(InsertUpdate.java:114)
2021/06/14 11:58:00 - Insert / update.0 -     at org.pentaho.di.trans.steps.insertupdate.InsertUpdate.processRow(InsertUpdate.java:299)
2021/06/14 11:58:00 - Insert / update.0 -     at org.pentaho.di.trans.step.RunThread.run(RunThread.java:62)
2021/06/14 11:58:00 - Insert / update.0 -     at java.lang.Thread.run(Unknown Source)
2021/06/14 11:58:00 - Insert / update.0 - Caused by: java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`dwsucos`.`fato_001`, CONSTRAINT `dim_produto_fato_001_fk` FOREIGN KEY (`Cod_Produto`) REFERENCES `dim_produto` (`Cod_Produto`) ON DELETE NO ACTION ON UPDATE NO ACTION)
2021/06/14 11:58:00 - Insert / update.0 -     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117)
2021/06/14 11:58:00 - Insert / update.0 -     at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
2021/06/14 11:58:00 - Insert / update.0 -     at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
2021/06/14 11:58:00 - Insert / update.0 -     at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092)
2021/06/14 11:58:00 - Insert / update.0 -     at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040)
2021/06/14 11:58:00 - Insert / update.0 -     at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1347)
2021/06/14 11:58:00 - Insert / update.0 -     at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025)
2021/06/14 11:58:00 - Insert / update.0 -     at org.pentaho.di.core.database.Database.insertRow(Database.java:1298)

Alguém consegue me ajudar?

3 respostas

Oii Pedro, tudo bem?

O erro é esse aqui:

Cannot add or update a child row: a foreign key constraint fails (dwsucos.fato_001, CONSTRAINT dim_produto_fato_001_fk FOREIGN KEY (Cod_Produto) REFERENCES dim_produto (Cod_Produto) ON DELETE NO ACTION ON UPDATE NO ACTION).

O erro retorna por conta de não estar encontrando a chave estrangeira da dimensão produto, que é o Cod_Produto.

Eu sugiro você rever as suas tabelas, se os campos se encontram ali.

Me avise qualquer coisa, tá bom? :)

Tambem estou com erro nesta fase

Estou com erro no Spoon, quando tento visualizar tabela de fato 001, rodei uma query no SQL Server da certo, porem no Spoon do erro :

Conexão : https://i.ibb.co/Nj5zZLX/conex-o.png

Tabela de Fato _ Spoon : https://i.ibb.co/D1LcW6B/Leitura-Tabela-de-Fato-001.png

Consulta dentro do SQL : https://i.ibb.co/Jk7HkK1/sql-server-fato-001.png

Erro : https://i.ibb.co/P4PB8pG/erro.png

solução!

Olá Maria, tudo bem?

Verifiquei a estrutura das tabelas em meu banco de dados, e está tudo normal.

Porém ao realizar algumas consultas vi que a inserção do campo Cod_Produto na tabela produtos estava "1000889.0" e o esperado pela tabela seria "1000889".

Com um update na tabela para remover essa casa decimal resolvi meu problema ;)

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software