문제

i have two tables ring and style i.e

CREATE TABLE IF NOT EXISTS `ring` (
  `jewelry_id` int(11) NOT NULL auto_increment,
  `ring_id` varchar(50) NOT NULL,
  `gender` varchar(10) NOT NULL,
  `description` text NOT NULL,
  `image` varchar(100) NOT NULL,
  `type` text NOT NULL,
  PRIMARY KEY  (`jewelry_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

the syle table is

CREATE TABLE IF NOT EXISTS `style` (
  `style_id` int(11) NOT NULL AUTO_INCREMENT,
  `style` text NOT NULL,
  `jewelry_id` int(11) NOT NULL,
  PRIMARY KEY (`style_id`),
  KEY `jewelry_id` (`jewelry_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

when i add a foreign key to the style table it give me error i.e

ALTER TABLE `style`
  ADD CONSTRAINT `style_ibfk_1` FOREIGN KEY (`jewelry_id`) REFERENCES `ring` (`jewelry_id`) ON DELETE CASCADE ON UPDATE CASCADE;

the error is

#1005 - Can't create table './j_jewelry/#sql-2c3b_750.frm' (errno: 150) (Details...</a>)
도움이 되었습니까?

해결책

MyISAM tables dont support foreign keys. Make both tables InnoDB.

다른 팁

For foreign key referencing the table type should be INNODB

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top