Jump to content

updating a foreign key in a table


adam291086

Recommended Posts

i have this table structure

CREATE  TABLE IF NOT EXISTS `job_preferences` (
  `JobTitles_idJobTitles` SMALLINT(6) NOT NULL ,
  `person_idUser` INT(10) UNSIGNED NOT NULL ,
  PRIMARY KEY (`JobTitles_idJobTitles`, `person_idUser`) ,
  CONSTRAINT `fk_JobPreferences_JobTitles`
    FOREIGN KEY (`JobTitles_idJobTitles` )
    REFERENCES `job_titles` (`idJobTitles` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_JobPreferences_person`
    FOREIGN KEY (`person_idUser` )
    REFERENCES `persons` (`idUser` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COMMENT = 'Persons select 6 job titles from 2 sectors \n';

CREATE INDEX fk_JobPreferences_JobTitles ON `job_preferences` (`JobTitles_idJobTitles` ASC) ;

CREATE INDEX fk_JobPreferences_person ON `job_preferences` (`person_idUser` ASC) ;

 

and i am trying to up date the table using this query

INSERT INTO `job_preferences` (JobTitles_idJobTitles,person_idUser) VALUES ('1','1')

 

and then putting it into the ez_sql php class

$query_job_preferences;
$data_job_preferences = $db->query($query_job_preferences, $output);

 

i get the error message

 

SQL/DB Error -- [Cannot add or update a child row: a foreign key constraint fails (`adamplo1_CASE/experiences`, CONSTRAINT `fk_Experiences_Persons` FOREIGN KEY (`Persons_idUser`) REFERENCES `persons` (`idUser`) ON DELETE NO ACTION ON UPDATE NO ACTION)]

 

How can i prevent the error? I know there is a persons id of 1 and a idJobTitle of 1 to.

 

Link to comment
https://forums.phpfreaks.com/topic/149865-updating-a-foreign-key-in-a-table/
Share on other sites

it turns out the database is updating but the error message

 

SQL/DB Error -- [Cannot add or update a child row: a foreign key constraint fails (`adamplo1_CASE/experiences`, CONSTRAINT `fk_Experiences_Persons` FOREIGN KEY (`Persons_idUser`) REFERENCES `persons` (`idUser`) ON DELETE NO ACTION ON UPDATE NO ACTION)]

 

and i don't know why?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.