我正试图建立数据库表并连接这些表格。 我确保我的数据类型相同。 我也确保,我的表格在加入科索沃信托公司之前进行。 任何建议都将受到高度赞赏。
SQL query:
ALTER TABLE `Member` ADD FOREIGN KEY ( memberId ) REFERENCES `Order_Head` ( `memberId` ) ;
MySQL said: Documentation
#1005 - Can t create table test2.#sql-184c_63 (errno: 150) (Details...)
-- ---
-- Table Order_Head
--
-- ---
DROP TABLE IF EXISTS `Order_Head`;
CREATE TABLE `Order_Head` (
`orderId` INTEGER NOT NULL AUTO_INCREMENT,
`memberId` INTEGER NOT NULL,
`date` DATE NOT NULL,
PRIMARY KEY (`orderId`, `memberId`)
);
-- ---
-- Table Member
--
-- ---
DROP TABLE IF EXISTS `Member`;
CREATE TABLE `Member` (
`memberId` INTEGER NOT NULL AUTO_INCREMENT,
`userName` VARCHAR(50) NOT NULL,
`password` VARCHAR(50) NOT NULL,
`email` VARCHAR(100) NOT NULL,
`isAdmin` BOOLEAN NOT NULL DEFAULT false,
PRIMARY KEY (`memberId`)
);
-- ---
-- Foreign Keys
-- ---
ALTER TABLE `Member` ADD FOREIGN KEY (memberId) REFERENCES `Order_Head` (`memberId`);
-- ---
-- Table Properties
-- ---
ALTER TABLE `Order_Head` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
ALTER TABLE `Member` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;