ERROR 1005(HY000)错误:150

时间:2017-08-20 06:49:27

标签: mysql-error-1005

我遇到了这个问题,许多帖子已经解决了这个问题,但没有一个问题显示我出错的地方。当我尝试以下操作时,我得到错误1005和errno 150;

约会结构:

        CREATE TABLE `appointments` (
        `appointmentID` int(11) NOT NULL AUTO_INCREMENT,
        `apptNum` tinyint(3) unsigned NOT NULL DEFAULT '1',
        `cwaID` int(11) NOT NULL DEFAULT '0',
        `siteID` int(11) DEFAULT NULL,
        `titleCode` varchar(25) NOT NULL,
        `apptPercentage` double DEFAULT '0',
        `status` varchar(2) CHARACTER SET utf8 DEFAULT NULL,
        `payRate` double DEFAULT '0',
        `rateCode` varchar(5) CHARACTER SET utf8 DEFAULT NULL,
        `locationInfo` varchar(100) CHARACTER SET utf8 DEFAULT NULL,
        `apptStartDate` date DEFAULT NULL,
        `apptEndDate` date DEFAULT NULL,
        `isPrimaryAppointment` varchar(1) CHARACTER SET utf8 NOT NULL 
          DEFAULT 'y',
        `lastModDate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE 
           CURRENT_TIMESTAMP,
        PRIMARY KEY (`appointmentID`),
        UNIQUE KEY `appointmentID` (`appointmentID`),
        UNIQUE KEY `cwaID-apptNum` (`cwaID`,`apptNum`),
        KEY `apptNum` (`apptNum`),
        KEY `siteID` (`siteID`),
        KEY `rateCode` (`rateCode`),
        KEY `cwaID` (`cwaID`),
        KEY `titleCode` (`titleCode`),
        CONSTRAINT `FK_employees_appointments` FOREIGN KEY (`cwaID`) REFERENCES
          `employees` (`cwaID`)
        ) ENGINE=InnoDB DEFAULT CHARSET=latin1

作业结构:

    CREATE TABLE `jobtitles` (
      `titleCode` varchar(25) CHARACTER SET utf8 NOT NULL,
      `jobTitle` varchar(255) CHARACTER SET utf8 NOT NULL,
      `unitID` varchar(10) CHARACTER SET utf8 NOT NULL,
      `scope` varchar(10) CHARACTER SET utf8 NOT NULL,
      `payPeriod` char(1) NOT NULL DEFAULT 'M',
      `maxPay` decimal(8,2) NOT NULL DEFAULT '0.00',
      `minPay` decimal(8,2) NOT NULL DEFAULT '0.00',
      PRIMARY KEY (`titleCode`),
      KEY `jobTitle` (`jobTitle`),
      KEY `scope` (`scope`),
      KEY `unitID` (`unitID`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1

我想为titleCode字段的约会添加一个外键:

    ALTER TABLE appointments ADD CONSTRAINT `FK_jobtitles_appointments` 
      FOREIGN KEY (`titleCode`) REFERENCES `jobtitles` (`titleCode`);

但是这次尝试使用errno 150生成ERROR 1005,这意味着外键不正确。

有什么建议吗?

0 个答案:

没有答案