PHPMyAdmin - InnoDB表不会加入

时间:2011-07-03 18:01:04

标签: mysql foreign-keys phpmyadmin

这是我的数据库结构:

    CREATE database mytvguide

    CREATE TABLE IF NOT EXISTS `channels` (
      `id` int(11) NOT NULL auto_increment,
      `channel1` varchar(255) NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

    CREATE TABLE IF NOT EXISTS `episodeairings` (
  `id` mediumint(255) unsigned NOT NULL auto_increment,
  `programme` varchar(255) collate utf8_unicode_ci NOT NULL,
  `channel` varchar(255) collate utf8_unicode_ci default NULL,
  `airdate` datetime default NULL,
  `displayair` datetime default NULL,
  `expiration` datetime default NULL,
  `epname` varchar(256) collate utf8_unicode_ci NOT NULL,
  `epno` mediumint(255) unsigned NOT NULL,
  `epseries` mediumint(255) unsigned NOT NULL,
  `setreminder` varchar(255) collate utf8_unicode_ci default NULL,
  PRIMARY KEY  (`id`),
  KEY `channel` (`channel`),
  KEY `programme` (`programme`),
  KEY `setreminder` (`setreminder`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC AUTO_INCREMENT=3 ;
INSERT INTO `episodeairings` (`id`, `programme`, `channel`, `airdate`, `displayair`, `expiration`, `epname`, `setreminder`) VALUES
(1, 'TV Programme 1', 'ITV2', '2011-07-09 22:35:00', '2011-06-30 22:35:00', '2011-06-30 23:05:00', 'Episode', '' , '', NULL),
(2, 'TV Programme 1', 'ITV2', '2011-07-10 02:25:00', '2011-07-01 02:25:00', '2011-07-01 02:55:00', 'EpisodeTest', '1', '2', NULL);
CREATE TABLE IF NOT EXISTS `episode` (
  `id` int(11) NOT NULL auto_increment,
  `epname` varchar(255) NOT NULL,
  `seriesnumber` int(11) NOT NULL,
  `episodenumber` int(11) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `epname` (`epname`),
  KEY `seriesnumber` (`seriesnumber`),
  KEY `episodenumber` (`episodenumber`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


INSERT INTO `episode` (`id`, `epname`, `seriesnumber`, `episodenumber`) VALUES
(1, 'Episode', 1, 1);

CREATE TABLE IF NOT EXISTS `programme1` (
  `id` int(11) NOT NULL auto_increment,
  `programme` varchar(255) NOT NULL default '<a href="pca1.php">Police, Camera, Action!</a>',
  PRIMARY KEY  (`id`),
  KEY `programme` (`programme`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;


INSERT INTO `programme1` (`id`, `programme`) VALUES
(1, '<a href="prog1.php">TV Programme 1</a>');

INSERT INTO `channels` (`id`, `channel`) VALUES
(1, '<a href="TV2.php">ITV2</a>');

出于某种原因,我无法链接episodeairings中的任何表格 - 即程序,频道,airdate,epname,epno,epseries 与其他表格中的表格 (程序,epname,seriesnumber,episodenumber)。 基本上,链接表根本不会发生下拉,就像它应该做的那样。

尽管事实上我的数据库是通过PHPmyadmin存储为InnoDB而且我设置了链接表。

为什么会这样,我该如何解决?

1 个答案:

答案 0 :(得分:0)

我不确定phpmyadmin是如何工作的,但我认为它要求你在表之间定义一些外键约束(例如使用alter table语句)。

请参见alter table docs:http://dev.mysql.com/doc/refman/5.1/en/alter-table.html