0

请看这段代码,我正在使用mysql。

create table `dictionary_one` (`dict_id` int(10) primary key)
engine = innodb;

create table `already_exists`(
  `pk_id`             int(10) primary key,
  `ref_dict_one_id`   int(10),
  constraint `Already_exists_ibfk_1` foreign key(`ref_dict_one_id`) references `dictionary_one`(`dict_id`)
);

到目前为止,似乎一切进展顺利。现在 - 添加引用另一个表的另一列。

create table `dictionary_two` (`dict_id` int(10) primary key)
engine = innodb;

alter table `already_exists` add column `ref_dict_two_id` int(10), add foreign key `Already_exists_ibfk_2`(`ref_dict_two_id`) references `dictionary_two`(`dict_id`);

没有语法错误,一切都做对了,但是:

ERROR 1050 (42S01): Table './test/already_exists' already exists
1 row in set (0.00 sec)

我的问题是……为什么?

4

1 回答 1

4
alter table `already_exists` 
  add column `ref_dict_two_id` int(10),

  add constraint `Already_exists_ibfk_2`
    foreign key (`ref_dict_two_id`) 
    references `dictionary_two`(`dict_id`);
于 2012-12-27T13:42:32.450 回答