0

我已经搜索了问题,但找不到解决方案。

它是一对一的关系,我对另一个对员工有 FK 的表也有同样的问题

我不断得到一个

  error 1005 error no 105

表结构

CREATE TABLE `staff` (
  `StaffNumber` varchar(5) NOT NULL,
  `Firstname` varchar(45) DEFAULT NULL,
  `Lastname` varchar(45) DEFAULT NULL,
  `Insertion` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`StaffNumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8


CREATE TABLE `airmarshall` (
  `weaponNumber` int(11) NOT NULL,
  `Nationality` varchar(45) NOT NULL,
  `Snumber` varchar(5) NOT NULL,
  `SnumberA` varchar(5) NOT NULL,
  PRIMARY KEY (`Snumber`,`SnumberA`),
  CONSTRAINT `staff_ibfk_1` FOREIGN KEY (`Snumber`) REFERENCES `staff` (`StaffNumber`)     
  ON DELETE CASCADE ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
4

1 回答 1

0
 In Mysql Server version: 5.1.60   


mysql> CREATE TABLE `staff` (   `StaffNumber` varchar(5) NOT NULL,   `Firstname` varchar(45) DEFAULT NULL,   `Lastname` varchar(45) DEFAULT NULL,   `Insertion` varchar(45) DEFAULT NULL,   PRIMARY KEY (`StaffNumber`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    Query OK, 0 rows affected (0.15 sec)


    mysql> CREATE TABLE `airmarshall` (
        ->   `weaponNumber` int(11) NOT NULL,
        ->   `Nationality` varchar(45) NOT NULL,
        ->   `Snumber` varchar(5) NOT NULL,
        ->   `SnumberA` varchar(5) NOT NULL,
        ->   PRIMARY KEY (`Snumber`,`SnumberA`),
        ->   CONSTRAINT `staff_ibfk_1` FOREIGN KEY (`Snumber`) REFERENCES `staff` (`StaffNumber`)     
        ->   ON DELETE CASCADE ON UPDATE CASCADE
        ->  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    Query OK, 0 rows affected (0.16 sec)

    mysql> show create table airmarshall;
    -----------------------------------+
    | airmarshall | CREATE TABLE `airmarshall` (
      `weaponNumber` int(11) NOT NULL,
      `Nationality` varchar(45) NOT NULL,
      `Snumber` varchar(5) NOT NULL,
      `SnumberA` varchar(5) NOT NULL,
      PRIMARY KEY (`Snumber`,`SnumberA`),
      CONSTRAINT `staff_ibfk_1` FOREIGN KEY (`Snumber`) REFERENCES `staff` (`StaffNumber`) ON DELETE CASCADE ON UPDATE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
于 2012-10-09T12:22:20.740 回答