Domanda

ho due tavoli ring e lo stile cioè

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;

tavolo syle è

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;

quando aggiungo una chiave esterna alla tabella stile che mi dia errore cioè

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

l'errore è

#1005 - Can't create table './j_jewelry/#sql-2c3b_750.frm' (errno: 150) (Details...</a>)
È stato utile?

Soluzione

tabelle MyISAM non supportano le chiavi esterne. Fare entrambe le tabelle InnoDB.

Altri suggerimenti

Per chiave esterna che fa riferimento il tipo di tabella dovrebbe essere INNODB

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top