Monday, 15 August 2011

database - How do I reference a composite primary key with a foreign key using MySQL -



database - How do I reference a composite primary key with a foreign key using MySQL -

i'm attempting setup foreign key in table cell_lines reference topographic_region column of composite primary key in table topographic_regions.

each time run lastly 3 lines of code trying add together foreign key, receive error code 1215: cannot add together foreign key constraint.

now, foreign key column name (topographic_region) in cell_lines matches 1 of composite primary key column names in topographic_regions, other composite primary key column name beingness topographic_region_id. need address both components of composite primary key when creating foreign key?

a follow problem i've tried addressing both components of composite primary key using composite foreign key constraint, , still presented error code 1215: cannot add together foreign key constraint.

what can solve problem, , there anymore info me provide in order so? i'm happy respond.

thanks reading. i'm new mysql.

create table topographic_regions( topographic_regions_id int not null auto_increment, topographic_region int(10), karyotypes varchar(255), constraint pk_topographicid primary key (topographic_regions_id, topographic_region) ); create table cell_lines( cell_lines_id int not null auto_increment, cell_line varchar(50), topographic_region int(10), constraint pk_cellid primary key (cell_lines_id, cell_line) ); alter table cell_lines add together foreign key (topographic_region) references topographic_regions(topographic_region);

this problem composite pks. in fact, autonumber topographic_region_id unique , should utilize pk, , fk. topographic_region sounds unique should add together unique index it.

mysql database primary-key foreign-key-relationship composite-primary-key

No comments:

Post a Comment