MySql表现不佳

时间:2012-12-27 13:31:51

标签: php mysql database

请看这个代码,我正在使用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)

我的问题是......为什么?

1 个答案:

答案 0 :(得分: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`);