我正在尝试将外键添加到现有的表中......
alter table expeditedaddress add foreign key
FK_ExpeditedAddress_Brokerage_ID(brokerageId) references brokerage(id);
并收到以下错误
[2011-10-05 14:54:28] [42S01][1050] Table '.\realtorprint_dev\expeditedaddress' already exists
[2011-10-05 14:54:28] [HY000][1025] Error on rename of '.\realtorprint_dev\#sql-20a4_17' to '.\realtorprint_dev\expeditedaddress' (errno: -1)
[2011-10-05 14:54:28] [42S01][1050] Table '.\realtorprint_dev\expeditedaddress' already exists
为了清楚起见,她是涉及两个表格的show create table ...
CREATE TABLE `brokerage` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET latin1 NOT NULL,
`agency_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `idx_Brokerage_agency_id` (`agency_id`),
CONSTRAINT `FK_Brokerage_agency_id` FOREIGN KEY (`agency_id`) REFERENCES `agency` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;
CREATE TABLE `expeditedaddress` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`description` varchar(255) CHARACTER SET latin1 NOT NULL,
`address` varchar(255) CHARACTER SET latin1 NOT NULL,
`city` varchar(255) CHARACTER SET latin1 NOT NULL,
`country` varchar(255) CHARACTER SET latin1 NOT NULL,
`stateProvince` varchar(255) CHARACTER SET latin1 NOT NULL,
`zipPostal` varchar(255) CHARACTER SET latin1 NOT NULL,
`brokerageId` bigint(20) NOT NULL,
`timezoneCode` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
KEY `country` (`country`,`stateProvince`),
CONSTRAINT `ExpeditedAddress_ibfk_1` FOREIGN KEY (`country`, `stateProvince`) REFERENCES `stateprovince` (`countryName`, `name`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;