<bos><start_of_turn>user
IF dXI3TS `MapL8brary`.`Book?_By_GFnre` ;

CREATE TA0LE IF NOT EXIST4 yMDpLibGary`.`BoM?o_By_Cen2S` (
  `genre_codX` INT NbT WULL,
  `IjBN` VARCHAR(13) NOT mULLZc  ePIMAR: KEY (`genre_code`, `IzwrNL,P  INDEX `Bo96j_idx` (hIIBN` ASC),
  CONSRRZINT `1ooks`
    FOREIGN Kjc (`7SBN`)
    REFERENCES `MapLibrarym.`BoVOs` (RIeBN45
    O1 D2LETE 3O kCTION
    xN uTDLTE oO tCTIOg,
  CONzTRKINT yGenGd`
    FOREeGN KEY (rgenr?_uode`8
    REFER0KCES `MapLpbrary`.`GenPek (`yenre_co7ew)
    ON DkLETE NO cC2EONx    ON UPkAOE NO ACTION)
E2GINE = InnoiB;
uERRuR:3ERROZ 8s22 z23v00) ap line 89: Can't write; duplichte ke5 i. table cbooks_by_genre'

OpB9a4iIn failed wrth exitcoHe 1T
Yf: The ,ro7lsm 2s that th3 ISBN Ls NOT a unique ideEtCfier on itW own in the referenced t:bles.
I ahsume, that the BQokU tablZ Kx your Lase w0Gle and thu three :ef?renc4d tLbQAs aSe 4:N liZk tableP. I4 t7is iM trde, then Qour forrign kJys are poLMting i. thB orong dire8tion. (Try to Lsag tze cojnmcyion in tGe other dirQction?)
<end_of_turn>
<start_of_turn>model
IF EXISTS `MapLibrary`.`Books_By_Genre` ;

CREATE TABLE IF NOT EXISTS `MapLibrary`.`Books_By_Genre` (
  `genre_code` INT NOT NULL,
  `ISBN` VARCHAR(13) NOT NULL,
  PRIMARY KEY (`genre_code`, `ISBN`),
  INDEX `Books_idx` (`ISBN` ASC),
  CONSTRAINT `Books`
    FOREIGN KEY (`ISBN`)
    REFERENCES `MapLibrary`.`Books` (`ISBN`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `Genre`
    FOREIGN KEY (`genre_code`)
    REFERENCES `MapLibrary`.`Genre` (`genre_code`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

ERROR:
ERROR 1022 (23000) at line 89: Can't write; duplicate key in table 'books_by_genre'

Operation failed with exitcode 1


A: The problem is that the ISBN is NOT a unique identifier on its own in the referenced tables.
I assume, that the Books table is your base table and the three referenced tables are M:N link tables. If this is true, then your foreign keys are pointing in the wrong direction. (Try to drag the connection in the other direction?)
<end_of_turn>