2012-12-27 4 views
0

Regardez ce code s'il vous plaît, j'utilise mysql.MySql se comporte mal

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`) 
); 

Il semble que tout se passe bien jusqu'à maintenant. Maintenant - ajoutez une autre colonne qui fait référence à une autre table.

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`); 

Aucune erreur de syntaxe, tout est bien fait, mais:

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

et ma question est ... pourquoi?

Répondre

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`); 
Questions connexes