mysql版本:Mysqlcluster 7.3.7
系统:windows 2008 R2
错误描述:
新建下面的表时,报错: 1215 – Cannot add foreign key constraint
CREATE TABLE `userreportrecord` (
`UniqueID` int(11) NOT NULL AUTO_INCREMENT,
`Reporter` varchar(50) DEFAULT NULL,
`Phone` varchar(50) DEFAULT NULL,
`ReportTime` datetime DEFAULT NULL,
`Address` varchar(100) DEFAULT NULL,
`Content` varchar(200) DEFAULT NULL,
`Sound` varchar(100) DEFAULT NULL,
`Pic` varchar(100) DEFAULT NULL,
`DealState` varchar(50) DEFAULT NULL,
`DealMethod` varchar(50) DEFAULT NULL,
`DealPerson` varchar(50) DEFAULT NULL,
`DealTime` datetime DEFAULT NULL,
`ProblemType` int(11) DEFAULT NULL,
`DealObject` int(11) DEFAULT NULL,
`ThermalMeterUserId` int(11) NOT NULL,
PRIMARY KEY (`UniqueID`),
KEY `ThermalMeterUserId` (`ThermalMeterUserId`),
CONSTRAINT `userreportrecord_ibfk_1` FOREIGN KEY (`ThermalMeterUserId`) REFERENCES `thermalmeteruser` (`UniqueID`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8;
-. 开始怀疑是`thermalmeteruser`这个表在`userreportrecord`的后面,但检查发现是在前面的,所以排除。
下面附上`thermalmeteruser`的表:
CREATE TABLE `thermalmeteruser` (
`UniqueID` int(11) NOT NULL AUTO_INCREMENT,
`Address` varchar(255) DEFAULT NULL,
`CalcMethod` int(11) NOT NULL,
`ChargeState` int(11) DEFAULT NULL,
`ConstractionArea` decimal(10,2) NOT NULL,
`ContractNumber` varchar(255) DEFAULT NULL,
`Floor` int(11) DEFAULT NULL,
`HeatingMeans` varchar(1) DEFAULT NULL,
`IDNumber` varchar(255) DEFAULT NULL,
`LevelType` int(11) DEFAULT NULL,
`Name` varchar(255) DEFAULT NULL,
`PersonCardId` varchar(255) DEFAULT NULL,
`Unit` int(11) DEFAULT NULL,
`UseArea` decimal(10,2) DEFAULT NULL,
`UserId` varchar(255) DEFAULT NULL,
`UserName` varchar(255) DEFAULT NULL,
`UserPhone` varchar(255) DEFAULT NULL,
`UserState` varchar(1) DEFAULT NULL,
`UserPosition` int(11) DEFAULT NULL,
`UserStyle` int(11) DEFAULT NULL,
`FeeProjectId` int(11) DEFAULT NULL,
`UnitUniqueID` int(11) NOT NULL,
`Balance` decimal(10,2) DEFAULT “”0.00″”,
`PassWord` varchar(255) DEFAULT NULL,
`UserDirection` int(11) DEFAULT NULL,
`AddressSorted` int(11) DEFAULT “”0″”,
PRIMARY KEY (`UniqueID`,`ConstractionArea`),
KEY `FK_ThermalMeterUser_BasicInfo` (`UserStyle`),
KEY `FK_ThermalMeterUser_BasicInfo1` (`UserPosition`),
KEY `FK_ThermalMeterUser_FeeProject` (`FeeProjectId`),
KEY `FK_ThermalMeterUser_Units` (`UnitUniqueID`),
KEY `UserDirection` (`UserDirection`),
CONSTRAINT `FK_ThermalMeterUser_BasicInfo` FOREIGN KEY (`UserStyle`) REFERENCES `basicinfo` (`UniqueID`),
CONSTRAINT `FK_ThermalMeterUser_BasicInfo1` FOREIGN KEY (`UserPosition`) REFERENCES `basicinfo` (`UniqueID`),
CONSTRAINT `FK_ThermalMeterUser_FeeProject` FOREIGN KEY (`FeeProjectId`) REFERENCES `feeproject` (`UniqueID`),
CONSTRAINT `FK_ThermalMeterUser_Units` FOREIGN KEY (`UnitUniqueID`) REFERENCES `units` (`UniqueID`),
CONSTRAINT `thermalmeteruser_ibfk_1` FOREIGN KEY (`UserDirection`) REFERENCES `basicinfo` (`UniqueID`)
) ENGINE=ndbcluster AUTO_INCREMENT=54566 DEFAULT CHARSET=utf8;
请大神帮忙看看是什么问题,谢谢!