sql - InnoDB and creating relationships for table - one will not join -


this database:

    -- host: localhost -- generation time: feb 04, 2011 @ 01:49 pm -- server version: 5.0.45 -- php version: 5.2.5  set sql_mode="no_auto_value_on_zero";  -- -- database: `myepguide` --  -- --------------------------------------------------------    -- -- table structure table `channel1` --  create table if not exists `channel1` (   `id` mediumint(255) not null auto_increment,   `channel` varchar(255) default null,   primary key  (`id`),   key `channel` using btree (`channel`) ) engine=innodb  default charset=latin1 auto_increment=4 ;  -- -- dumping data table `channel1` --  insert `channel1` (`id`, `channel`) values (1, '<a href="channel/bbcone.php">bbc one</a>'), (3, '<a href="channel/itv1.php"><i>itv1</i></a>'), (2, '<a href="channel/itv2.php"><i>itv2 </i></a>');  -- --------------------------------------------------------  -- -- table structure table `myepguide` --  create table if not exists `myepguide` (   `id` mediumint(9) not null auto_increment,   `programme` varchar(255) not null,   `channel` varchar(255) default null,   `airdate` datetime not null,   `displayair` datetime not null,   `expiration` datetime not null,   `episode` varchar(255) default '',   `setreminder` varchar(255) not null default '<img src="alert.gif" height="16" width="22"> <a href="setreminder.php" alt="set reminder" target="_top">set reminder</a>',   primary key  (`id`),   key `programme1` using btree (`programme`),   key `channel2` using btree (`channel`),   key `episode` (`episode`) ) engine=innodb  default charset=latin1 auto_increment=3 ;  -- -- dumping data table `myepguide` --  insert `myepguide` (`id`, `programme`, `channel`, `airdate`, `displayair`, `expiration`, `episode`, `setreminder`) values (1, '<a href="programmes/casualty.php">casualty</a>', '<a href="lib/channel/itv1"><i>bbc 1 </i></a>', '2011-05-18 14:30:00', '2011-05-18 14:30:00', '2011-05-18 15:00:00', 'no fjords in finland', '<img src="alert.gif" height="16" width="22"> <a href="setreminder.php" alt="set reminder" target="_top">set reminder</a>');  -- --------------------------------------------------------  -- -- table structure table `episode` --  create table if not exists `episode` (   `id` mediumint(9) not null auto_increment,   `episode` varchar(255) default null,   primary key  (`id`),   key `episode` using btree (`episode`) ) engine=innodb  default charset=latin1 auto_increment=3 ;  -- -- dumping data table `episode` --  insert `episode` (`id`, `episode`) values (1, 'no fjords in finland'), (2, 'casualty 25th special'), (3, '<a href="holby1.php">palimpsest</a>');  -- --------------------------------------------------------  -- -- table structure table `programme` --  create table if not exists `programme` (   `id` mediumint(255) not null auto_increment,   `programme` varchar(255) default null,   primary key  (`id`),   key `programme1` using btree (`programme`) ) engine=innodb  default charset=latin1 auto_increment=2 ;  -- -- dumping data table `programme` --  insert `programme` (`id`, `programme`) values (1, '<a href="programmes/casualty.php">casualty</a>');  -- -- constraints dumped tables --  -- -- constraints table `myepguide` -- alter table `myepguide`   add constraint `myepguide_ibfk_1` foreign key (`programme`) references `myepguide` (`programme`) on update cascade,   add constraint `myepguide_ibfk_2` foreign key (`channel`) references `channel1` (`channel`) on delete set null on update cascade; 

i cannot 'episode` table link in table myepguide reason, in phpmyadmin says "relation not added".

deleting , re-creating did not work either, how can fix this?

all stored in innodb format can't understand why happened.

any appreciated!

as mentioned in comment, not quite sure trying link here, starters use idea of possible relationships.

enter image description here

edit

create table tvseries (       tvseriesid int not null auto_increment --  , other fields here ) engine=innodb ; alter table tvseries       add constraint pk_tvseries primary key (tvseriesid) ;  create table episode (       tvseriesid int not null     , episodeno  int not null --  , other fields here ) engine=innodb ; alter table episode       add constraint  pk_episode primary key (tvseriesid, episodeno)     , add constraint fk1_episode foreign key (tvseriesid) references tvseries (tvseriesid) ;   create table channel (       channelid int not null --  , other fields here ) engine=innodb ; alter table channel       add constraint pk_channel primary key (channelid);   create table programme (       channelid  int      not null     , starttime  datetime not null     , tvseriesid int      not null     , episodeno  int      not null --  , other fields here ) engine=innodb ; alter table programme       add constraint  pk_programme primary key (channelid, starttime)     , add constraint fk1_programme foreign key (channelid) references channel (channelid)     , add constraint fk2_programme foreign key (tvseriesid, episodeno) references episode (tvseriesid, episodeno) ;   create table myepisodeguide (       tvseriesid  int      not null     , episodeno   int      not null     , channelid   int      not null     , starttime   datetime not null     , setreminder int      not null  --  , other fields here ) engine=innodb ; alter table myepisodeguide       add constraint  pk_myepisodeguide primary key (tvseriesid, episodeno, channelid, starttime)     , add constraint fk1_myepisodeguide foreign key (tvseriesid, episodeno) references episode (tvseriesid, episodeno)     , add constraint fk2_myepisodeguide foreign key (channelid, starttime)  references programme (channelid, starttime) ; 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -