MySQL Cannot Add Foreign Key Constraint

后端 未结 22 1811
时光取名叫无心
时光取名叫无心 2020-11-22 08:35

So I\'m trying to add Foreign Key constraints to my database as a project requirement and it worked the first time or two on different tables, but I have two tables on which

22条回答
  •  盖世英雄少女心
    2020-11-22 08:52

    In my case, there was a syntax error which was not explicitly notified by MySQL console upon running the query. However, SHOW ENGINE INNODB STATUS command's LATEST FOREIGN KEY ERROR section reported,

      Syntax error close to:
    
      REFERENCES`role`(`id`) ON DELETE CASCADE) ENGINE = InnoDB DEFAULT CHARSET = utf8
    

    I had to leave a whitespace between REFERENCES and role to make it work.

提交回复
热议问题