1

外部キーの作成にこの奇妙な問題があります。

与えられた 2 つのテーブル:

CREATE TABLE IF NOT EXISTS `groupdeals` (
  `groupdeals_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `product_id` int(10) NOT NULL,
  `merchant_id` int(11) NOT NULL,
  `minimum_qty` int(11) NOT NULL,
  `maximum_qty` int(11) NOT NULL,
  `target_met_email` int(11) NOT NULL,
  `coupon_barcode` text NOT NULL,
  `coupon_merchant_address` int(11) NOT NULL,
  `coupon_merchant_contact` int(11) NOT NULL,
  `coupon_expiration_date` date DEFAULT NULL,
  `coupon_price` int(11) NOT NULL,
  `coupon_fine_print` int(11) NOT NULL,
  `coupon_highlights` int(11) NOT NULL,
  `coupon_merchant_description` int(11) NOT NULL,
  `coupon_business_hours` int(11) NOT NULL,
  `coupon_merchant_logo` int(11) NOT NULL,
  `coupon_additional_info` text NOT NULL,
  `position` int(11) NOT NULL,
  PRIMARY KEY (`groupdeals_id`),  
  KEY `groupdeals_id` (`groupdeals_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `groupdeals_coupons` (
  `coupon_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `groupdeals_id` int(11) NOT NULL,
  `order_item_id` int(11) NOT NULL,
  `coupon_code` varchar(255) NOT NULL DEFAULT '',
  `redeem` varchar(255) NOT NULL DEFAULT '',
  `status` varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY (`coupon_id`),
  KEY `fk_groupdeals_coupons_groupdeals1_idx` (`groupdeals_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

次のクエリを実行して、外部キーを追加しようとしています。

ALTER TABLE `groupdeals_coupons` 
ADD CONSTRAINT `fk_groupdeals_coupons_groupdeals1`
  FOREIGN KEY (`groupdeals_id`)
  REFERENCES `groupdeals` (`groupdeals_id`)
  ON DELETE CASCADE
  ON UPDATE CASCADE;

私が受け取るのはエラーだけです:

#1215 - Cannot add foreign key constraint

エンジンの innodb ステータスを表示

------------------------
LATEST FOREIGN KEY ERROR
------------------------
2013-08-17 13:47:49 7ff5dbb2c700 Error in foreign key constraint of table xxxxx/#sql-7b23_282b1a:

 FOREIGN KEY (`groupdeals_id`)
 REFERENCES `groupdeals` (`groupdeals_id`)
 ON DELETE CASCADE
 ON UPDATE CASCADE:
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html
for correct foreign key definition.

列 groupdeals.groupdeals_id は主要なものなので、どこに問題があるのか​​ 本当にわかりません:|

ヒントはありますか?

サーバーの種類: Percona サーバー サーバーのバージョン: 5.6.11-rc60.3-log - Percona サーバー (GPL)、リリース 60.3

4

2 に答える 2