Error while performing Mysql update with composite keys

Asked

Viewed 41 times

1

I have the following table in Mysql inserir a descrição da imagem aqui

I tried all the ways to perform an update sql but every time returns the same error below.

Cannot add or update a Child Row: a Foreign key Constraint fails

This is the update sql

UPDATE ACDM_TREI_RLZD_ALU_EXCC SET EST_EXCC = 'OK' WHERE CD_ALU = 1 AND TS_RLZC_TREI = '2019-02-16' AND NR_EXCC= 1

This is the table on which it is dependent inserir a descrição da imagem aqui

Any idea what I might be missing?

  • This EST_EXCC column is referenced in another table?

  • No. She’s a regular column

  • Sends the create table of this table.

  • I edited the question and put the create

  • The update was normal here. UPDATE ACDM_TREI_RLZD_ALU_EXCC SET EST_EXCC = 'OK' WHERE CD_ALU = 1 AND date(TS_RLZC_TREI) = '2019-02-16' AND NR_EXCC= 1

  • anything sends the other Tables he uses as Foreign

  • I put in question the related tables

Show 3 more comments

1 answer

1


In the create below you are using the column TS_RLZC_TREI table ACDM_TREI_RLZD_ALU_EXCC as a foreign key. However, the value of it that is a reference is updating whenever you give an update due to the create command.

#`TS_RLZC_TREI` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),

The create would look like this:

CREATE TABLE IF NOT EXISTS `ACDM_TREI_RLZD_ALU_EXCC` (
  `CD_ALU` bigint(20) NOT NULL,
  `TS_RLZC_TREI` timestamp NOT NULL DEFAULT current_timestamp(), /*A alteração está aqui*/
  `NR_EXCC` int(11) NOT NULL,
  `CD_EXCC` int(11) NOT NULL,
  `QT_SRE` int(11) NOT NULL,
  `QT_RPTC` int(11) NOT NULL,
  `HR_DESC` time DEFAULT NULL,
  `QT_KG` decimal(15,3) DEFAULT NULL,
  `HR_DRCO` time DEFAULT NULL,
  `TX_OBS` varchar(255) DEFAULT NULL,
  `TS_ULT_ALT` timestamp NOT NULL DEFAULT current_timestamp(),
  `CD_USU_RSP` int(11) NOT NULL DEFAULT 0,
  `EST_EXCC` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.