错误121表示存在外键约束错误。由于您使用的是InnoDB,因此您可以
SHOW ENGINE INNODBSTATUS在运行失败的查询后使用,以在本
LATEST FOREIGN KEY ERROR节中获得解释。我自己运行了SQL,我得到了:
------------------------LATEST FOREIGN KEY ERROR------------------------101210 14:55:50 Error in foreign key constraint creation for table `regula`.`Reservation`.A foreign key constraint of name `regula`.`prjId`already exists. (Note that internally InnoDB adds 'databasename'in front of the user-defined constraint name.)Note that InnoDB's FOREIGN KEY system tables storeconstraint names as case-insensitive, with theMySQL standard latin1_swedish_ci collation. If youcreate tables or databases whose names differ only inthe character case, then collisions in constraintnames can occur. Workaround: name your constraintsexplicitly with unique names.
基本上,您需要在最后一个表中给prjId约束名称一个唯一的名称。约束/外键名称是数据库的全局名称,因此不能在不同的表中重复使用。只需更改最后一个
ConSTRAINT `prjId`
至
ConSTRAINT `prjId2`



