我相信这与我的外键有关,但我真的不明白出了什么问题。这是我得到的错误:
第 1 行的错误 1005 (HY000):无法创建表 'cse156.Accounts' (errno: 150)
CREATE TABLE `AccountType`(
`AccountType` varchar(255)NOT NULL,
`Label` varchar(255) NOT NULL,
`BaseAPR` float(10) NOT NULL DEFAULT'0.0',
`BaseFee` float(10) NOT NULL DEFAULT '0.0',
PRIMARY KEY (`AccountType`)
);
CREATE TABLE `Accounts`(
`AccountID` int(10) NOT NULL DEFAULT '0',
`AccountType` varchar(255) NOT NULL,
`Balance` float(10) Default '0',
`DateofCreation` varchar(255),
`AprAdjustment` float(10) NOT NULL DEFAULT'0.0',
`FeeAdjustment` float(10) NOT NULL DEFAULT'0.0',
PRIMARY KEY (`AccountID`),
FOREIGN KEY (`AccountType`) REFERENCES AccountTypes(`AccountType`)
);
INSERT INTO `Accounts` VALUES (867001,'RIRA08',543.23,'2008/03/01',0.0,0.0),(530900,'RIRA08',123.00,'2008/04/05',0.125,3.50),(321455,'GCD1009',1232123.12,'2002/01/05',-1.25,0.0),(392108,'RPSA',450.00,'1994/06/09',0.0,15.00),(32948,'RPSA',25.00,'1997/08/03',0.25,2.50),(90490001,'GCD1009',1000000.50,'2005/03/06',1.25,0.50);
INSERT INTO `AccountType` VALUES('RIRA08','Roth IRA',2.05,10.00),('GCD1009','Golden Years Certificate of Deposit',5.05,0.00),('MIRA09','Roth IRA',3.2,0.00),('RPSA','Savings Advantage',1.85,0.00);
DROP TABLE IF EXISTS `Customers`;
CREATE TABLE `Customers` (
`CustomerID` int(11) NOT NULL DEFAULT '0',
`CustomerFirstName` varchar(255) NOT NULL,
`CustomerLastName` varchar(255) NOT NULL,
`Address` varchar(255) NOT NULL,
`Email` varchar(255) NOT NULL,
`Flag` varchar(1) NOT NULL,
PRIMARY KEY (`CustomerID`),
FOREIGN KEY (`AccountID`) REFERENCES Accounts(`AccountID`)
);
INSERT INTO Customers VALUES (829304,'Anthony','Rizzo','123 A Street,Omaha, NE, 68116','rizzo@cubs.com,arizzo@iowacubs.com','S'),(423904,'Starlin','Castro','456 B Ave., Chicago, IL, 67777','scastro@gmail.com','P'),(423431,'Darwin','Barney','7G North,Le City,ON,E5F456','dbar@yahoo.com,barn@mlb.com,db01@unl.edu','S');
DROP TABLE IF EXISTS `CustomerAccounts`;
CREATE TABLE `CustomerAccounts` (
`CustomerID` int(11) NOT NULL DEFAULT '0',
`AccountID` int(11) DEFAULT '0',
FOREIGN KEY (`AccountID`) REFERENCES Accounts(`AccountID`),
FOREIGN KEY (`CustomerID`) REFERENCES Customers(`CustomerID`)
);
INSERT INTO `CustomerAccounts`VALUES(829304,0), (423904,867001),(423904,530900),(423431,90490001),(423431,32948),(423431,392108);