MySQL Forums
Forum List  »  French

[MySQL] Erreur ForeignKey
Posted by: Cedric Bourgeon
Date: January 23, 2009 02:47AM

Bonjour,

J'ai généré un script de creation de table avec Workbench
et lors de l'exécution de ce script SQL dans l'admin de mysql, une erreur est dégagée.

En exécutant ensuite le script action par action, j'ai repéré que le problème venait de la dernière requête de création d'une foreignkey sur un des champs de ma table (alors q pour les autres tables et meme pr d'autres foreignkeys au sein de cette table, aucune erreur n'a été soulevée)

voici le script généré par Workbench [c'est la foreignkey 'fk_periode' qui pose probleme]:

CREATE TABLE IF NOT EXISTS `mydb`.`CE` (
`ce_id` INT NOT NULL ,
`cours_code` VARCHAR(45) NOT NULL ,
`etudiant_id` INT NOT NULL ,
`ce_nb_heures_semaine` FLOAT NULL ,
`ce_nb_heures_total` FLOAT NULL ,
`statut_id` INT NOT NULL ,
`periode_id` INT NOT NULL ,
PRIMARY KEY (`ce_id`, `cours_code`, `etudiant_id`) ,
CONSTRAINT `fk_cours`
FOREIGN KEY (`cours_code` )
REFERENCES `mydb`.`Cours` (`cours_code` )
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT `fk_etudiant`
FOREIGN KEY (`etudiant_id` )
REFERENCES `mydb`.`Etudiants` (`etudiant_id` )
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_statut`
FOREIGN KEY (`statut_id` )
REFERENCES `mydb`.`Statut` (`statut_id` )
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT `fk_periode`
FOREIGN KEY (`periode_id` )
REFERENCES `mydb`.`Periodes` (`periode_id` )
ON DELETE NO ACTION
ON UPDATE CASCADE);

et voici le code correspondant à la création de la table à laquelle la foreignKey fait référence:

CREATE TABLE IF NOT EXISTS `Periodes` (
`periode_id` INT NOT NULL AUTO_INCREMENT ,
`periode_nom` VARCHAR(45) NULL ,
PRIMARY KEY (`periode_id`) );

Merci d'avance à ceux qui pourront m'aider

Options: ReplyQuote


Subject
Views
Written By
Posted
[MySQL] Erreur ForeignKey
6159
January 23, 2009 02:47AM
2871
January 23, 2009 03:01AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.