title: Error 1215: Cannot add foreign key constraint
body: <p>I built a database with mySql Workbench, but when I try to forward engineer my model to the server, I get the following error : </p>
  
  <blockquote>
    <p>ERROR: Error 1215: Cannot add foreign key constraint</p>
  </blockquote>
  
  <p>followed by the definition of the table where the foreign key is defined, <code>salaire_annee_ca</code></p>
  
  <p>I read similar topics to identify the usual causes for this error, and checked :</p>
  
  <ul>
  <li>if the foreign key defined in <code>salaire_annee_ca</code> references the primary key of another table, which it does</li>
  <li>if something in the code allowed my key to be null, which it doesn't</li>
  <li>if the types of the reference and of the foreign key were the same</li>
  </ul>
  
  <p>It seems to me that all these conditions are ok, so I don't understand why I still get that message. Here are the definitions of my tables :</p>
  
  <p>These are the two main ones :</p>
  
  <hr>
  
  <pre><code>-- Table `credit_impot_db`.`salaires_annee`
  -- -----------------------------------------------------
  CREATE  TABLE IF NOT EXISTS `credit_impot_db`.`salaires_annee` (
    `salaire_annee_id` INT(11) NOT NULL ,
    `salaire_annuel` DOUBLE NOT NULL DEFAULT 0 ,
    `heures_travaillees` DOUBLE NOT NULL DEFAULT 0 ,
    `pourcentage_rsde` DOUBLE NOT NULL DEFAULT 0 ,
    `jours_travailles` INT(3) NOT NULL DEFAULT 0 ,
    PRIMARY KEY (`salaire_annee_id`) ,
    CONSTRAINT `salaire_annee_id`
      FOREIGN KEY (`salaire_annee_id` )
      REFERENCES `credit_impot_db`.`employes_ac` (`employe_ac_id` )
      ON DELETE CASCADE
      ON UPDATE CASCADE)
  ENGINE = InnoDB;
  
  This one is at the origin of the message :
  -- -----------------------------------------------------
  -- Table `credit_impot_db`.`salaire_annee_ca`
  -- -----------------------------------------------------
  CREATE  TABLE IF NOT EXISTS `credit_impot_db`.`salaire_annee_ca` (
    `salaire_annee_ca_id` INT(11) NOT NULL ,
    PRIMARY KEY (`salaire_annee_ca_id`) ,
    CONSTRAINT `salaire_annee_ca_id`
      FOREIGN KEY (`salaire_annee_ca_id` )
      REFERENCES `credit_impot_db`.`salaires_annee` (`salaire_annee_id` )
      ON DELETE CASCADE
      ON UPDATE CASCADE)
  ENGINE = InnoDB;
  </code></pre>
  
  <p>And the following two are also referenced :</p>
  
  <pre><code>-- -----------------------------------------------------
  -- Table `credit_impot_db`.`employes`
  -- -----------------------------------------------------
  CREATE  TABLE IF NOT EXISTS `credit_impot_db`.`employes` (
    `employe_id` INT(11) NOT NULL AUTO_INCREMENT ,
    `employe_nom` VARCHAR(255) NOT NULL ,
    `employe_prenom` VARCHAR(255) NOT NULL ,
    `employe_fonction` VARCHAR(255) NULL ,
    `employe_experience` VARCHAR(255) NULL DEFAULT NULL ,
    PRIMARY KEY (`employe_id`) )
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `credit_impot_db`.`employes_ac`
  -- -----------------------------------------------------
  CREATE  TABLE IF NOT EXISTS `credit_impot_db`.`employes_ac` (
    `employe_ac_id` INT(11) NOT NULL AUTO_INCREMENT ,
    `fk_employe_ac_employe_id` INT(11) NULL ,
    `fk_employe_ac_ac_id` INT(11) NULL ,
    PRIMARY KEY (`employe_ac_id`) ,
    INDEX `fk_employe_ac_employe_id_idx` (`fk_employe_ac_employe_id` ASC) ,
    INDEX `fk_employe_ac_ac_id_idx` (`fk_employe_ac_ac_id` ASC) ,
    CONSTRAINT `fk_employe_ac_employe_id`
      FOREIGN KEY (`fk_employe_ac_employe_id` )
      REFERENCES `credit_impot_db`.`employes` (`employe_id` )
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_employe_ac_ac_id`
      FOREIGN KEY (`fk_employe_ac_ac_id` )
      REFERENCES `credit_impot_db`.`dossier_client` (`ac_id` )
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  </code></pre>
  
  <p>Any help would be appreciated!</p>