データベースを作成し、それを2つのデータベースに接続したい。しかし、2 番目のデータベース (time_shift テーブル) への外部キーをいつ作成するかはわかりません。常にエラー 150 が発生します。
テーブルの構造は次のとおりoutlet
です。
そして、これはテーブルの構造ですtime_shift
:
そして、これは新しいテーブルを作成するためのクエリtide_cart
です:
create table `tide_chart` (
`id` int(10) not null auto_increment primary key,
`date` date null,
`outletId` int(11) not null,
`timeShiftId` int(11) not null,
`value` varchar(255) not null,
unique (`date`, `outletId`, `timeShiftId`),
foreign key (`outletId`) references `outlet`(`id`)
ON update cascade ON delete cascade,
foreign key (`timeShiftId`) references `time_shift`(`id`)
ON update cascade ON delete cascade
) engine=innoDB;
外部キーをテーブルに接続しようとするとエラーが発生する理由を教えてくださいtime_shift
。
更新: および のダンプ エクスポート構造テーブルをoutlet
追加time_shift
:
CREATE TABLE `outlet` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
CREATE TABLE `time_shift` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`time_start` time NOT NULL,
`time_end` time NOT NULL,
`is_active` tinyint(4) NOT NULL DEFAULT '1',
`ref_area` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
KEY `ref_area` (`ref_area`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;