phpmyadmin - MySQL unique index replacing one foreign key -



phpmyadmin - MySQL unique index replacing one foreign key -

i have pivot table named pivot maps tablea tableb`.

pivot has next fields: ta_id, tb_id.

i have 2 foreign keys - 1 on each field.

1) pivot_ta_id_foreign ta_id references id on tablea

2) pivot_tb_id_foreign tb_id references id on tableb

now when go add together 1 unique index on both columns so:

alter table 'pivot' add together unique 'pivot_ta_id_tb_id_unique' ('ta_id', 'tb_id')

the pivot_ta_id_foreign index disappears.

i need both foreign indexes , unique on 2 columns.

your can either utilize alter table command (you not need quotes, have incorrectly typed) or include the unique constraint within pivot table definition:

alter table pivot add together unique pivot_ta_id_tb_id_unique (ta_id, tb_id); or create table pivot( ta_id int, tb_id int, foreign key(ta_id) references tablea(id), foreign key(tb_id) references tableb(id), constraint pivot_ta_id_tb_id_unique unique (ta_id, tb_id) );

mysql phpmyadmin innodb

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -