Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql InnoDB和为table-one创建关系将不会联接_Sql_Mysql_Database_Phpmyadmin_Innodb - Fatal编程技术网

Sql InnoDB和为table-one创建关系将不会联接

Sql InnoDB和为table-one创建关系将不会联接,sql,mysql,database,phpmyadmin,innodb,Sql,Mysql,Database,Phpmyadmin,Innodb,这是我的数据库: -- Host: localhost -- Generation Time: Feb 04, 2011 at 01:49 PM -- Server version: 5.0.45 -- PHP Version: 5.2.5 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `myepguide` -- -- --------------------------------------------------

这是我的数据库:

    -- Host: localhost
-- Generation Time: Feb 04, 2011 at 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 for 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 for table `channel1`
--

INSERT INTO `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 for 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 a 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 for table `myepguide`
--

INSERT INTO `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 One </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 a reminder" target="_top">Set Reminder</a>');

-- --------------------------------------------------------

--
-- Table structure for 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 for table `episode`
--

INSERT INTO `episode` (`id`, `episode`) VALUES
(1, 'No Fjords in Finland'),
(2, 'Casualty 25th Special'),
(3, '<a href="Holby1.php">Palimpsest</a>');

-- --------------------------------------------------------

--
-- Table structure for 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 for table `programme`
--

INSERT INTO `programme` (`id`, `programme`) VALUES
(1, '<a href="programmes/casualty.php">Casualty</a>');

--
-- Constraints for dumped tables
--

--
-- Constraints for 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;
--主机:本地主机
--生成时间:2011年2月4日下午1:49
--服务器版本:5.0.45
--PHP版本:5.2.5
设置SQL\u MODE=“零上无自动值”;
--
--数据库:`myepguide`
--
-- --------------------------------------------------------   
--
--表'channel1的表结构`
--
如果“channel1”不存在,则创建表(
`id`mediumint(255)非空自动增量,
`通道'varchar(255)默认为空,
主键(`id`),
使用BTREE(`channel`)键`channel`)
)ENGINE=InnoDB默认字符集=latin1自动增量=4;
--
--正在转储表'channel1'的数据`
--
插入到'channel1'('id','channel')值中
(1, ''),
(3, ''),
(2, '');
-- --------------------------------------------------------
--
--表` myepguide'的表结构`
--
如果不存在“myepguide”,则创建表(
`id`mediumint(9)非空自动增量,
`程序'varchar(255)不为空,
`通道'varchar(255)默认为空,
`airdate`datetime不为空,
`displayair`datetime不为空,
`expiration`datetime不为空,
`插曲“varchar(255)默认值”,
`SetRemembers`varchar(255)非空默认值“”,
主键(`id`),
使用BTREE(`programme1`)键`programme1`,
使用BTREE(`channel`)键'channel2',
键“插曲”(“插曲”)
)引擎=InnoDB默认字符集=拉丁1自动增量=3;
--
--正在转储表“myepguide”的数据`
--
在“myepguide”(`id`、`programme`、`channel`、`airdate`、`displayair`、`expiration`、`eption`、`setrementer`)值中插入
(1),“2011-05-18 14:30:00”,“2011-05-18 14:30:00”,“2011-05-18 15:00:00”,“芬兰没有峡湾”,等等);
-- --------------------------------------------------------
--
--表“”的表结构`
--
如果“事件”不存在,则创建表(
`id`mediumint(9)非空自动增量,
`插曲'varchar(255)默认为空,
主键(`id`),
使用BTREE(`spice`)键'spice`)
)引擎=InnoDB默认字符集=拉丁1自动增量=3;
--
--正在转储表“”的数据`
--
插入到“插曲”(`id`,`SPICE`)值中
(1,“芬兰没有峡湾”),
(2,“特别事故”),
(3, '');
-- --------------------------------------------------------
--
--表`方案的表结构`
--
如果“程序”不存在,则创建表(
`id`mediumint(255)非空自动增量,
`程序`varchar(255)默认为空,
主键(`id`),
使用BTREE(`programme1`键)
)引擎=InnoDB默认字符集=拉丁1自动增量=2;
--
--表`方案的倾销数据`
--
在“程序”(`id`,`Program`)值中插入
(1, '');
--
--转储表的约束
--
--
--表'myepguide'的约束`
--
ALTER TABLE`myepguide`
在更新级联上添加约束“myepguide_ibfk_1”外键(`program`)引用“myepguide`”(`program`),
在DELETE上添加约束'myepguide_ibfk_2'外键('channel`)引用'channel1`('channel`),在更新级联上设置NULL;
由于某种原因,我无法让“插曲”表链接到myepguide表中的插曲,在Phpmyadmin中,它总是说“未添加关系”

删除和重新创建它也不起作用,因此如何修复此问题

所有文件都以InnoDB格式存储,因此我无法理解为什么会发生这种情况


感谢您的帮助

如评论中所述,我不太确定您想在这里链接什么,因此对于初学者,您可以使用此链接了解可能的关系

编辑

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

外键应该链接到主键,或者可能是唯一的列。您正在将myepguide链接到自身?你能解释一下你想要建立什么样的关系吗?节目应该列出什么?我的《插曲指南》应该展示什么?@Damir Sudarevic-有一些主键,即插曲和节目表中的id字段。在phpmyadmin中我该如何做到这一点?