Ciao,

mentre riesco a creare la giusta relazione tra la tabella details e details_options, non riesco a farlo per details e options.

Mi spiego meglio. Cancellando un record contenuto nella tabella details, automaticamente cancello tutti i records in details_options che hanno una relazione con la prima tabella.

Vorrei fare la stessa cosa con la tabella options. Cancellando un record da essa, vorrei cancellare tutti i record che hanno una relazione nella tabella details.

L'errore che ricevo è il seguente:

#1452 - Cannot add or update a child row: a foreign key constraint fails (`regiaimmobiliare_collaction/#sql-9f8_94`, CONSTRAINT `#sql-9f8_94_ibfk_1` FOREIGN KEY (`option_cod`) REFERENCES `options` (`id`) ON DELETE CASCADE)

Codice PHP:
--
-- 
Struttura della tabella `details`
--

CREATE TABLE IF NOT EXISTS `details` (
  `
idint(11NOT NULL auto_increment,
  `
option_codint(11NOT NULL,
  `
namevarchar(150character set latin1 NOT NULL,
  `
urlvarchar(200character set latin1 NOT NULL,
  `
createdint(11NOT NULL,
  `
lasteditint(11NOT NULL,
  `
statusbinary(1NOT NULL,
  `
languagechar(8character set latin1 NOT NULL default 'italiano',
  `
type_valuetext character set latin1 NOT NULL,
  
PRIMARY KEY  (`id`),
  
KEY `option_cod` (`option_cod`)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='InnoDB free: 38912 kB; InnoDB free: 38912 kB; InnoDB free: 3' AUTO_INCREMENT=98 ;

--
-- 
Struttura della tabella `details_options`
--

CREATE TABLE IF NOT EXISTS `details_options` (
  `
idint(11NOT NULL auto_increment,
  `
detail_codint(11NOT NULL,
  `
namevarchar(150character set latin1 NOT NULL,
  `
urlvarchar(200character set latin1 NOT NULL,
  `
createdint(11NOT NULL,
  `
lasteditint(11NOT NULL,
  `
statusbinary(1NOT NULL default '1',
  `
languagechar(8character set latin1 NOT NULL default 'italiano',
  
PRIMARY KEY  (`id`),
  
KEY `details_options_keys` (`detail_cod`)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='InnoDB free: 38912 kB; InnoDB free: 38912 kB; InnoDB free: 3' AUTO_INCREMENT=118 ;

--
-- 
Struttura della tabella `options`
--

CREATE TABLE IF NOT EXISTS `options` (
  `
idint(11NOT NULL auto_increment,
  `
namevarchar(150character set latin1 NOT NULL,
  `
urlvarchar(200character set latin1 NOT NULL,
  `
createdint(11NOT NULL,
  `
lasteditint(11NOT NULL,
  `
statusbinary(1NOT NULL,
  `
languagechar(8character set latin1 NOT NULL default 'italiano',
  
PRIMARY KEY  (`id`)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='InnoDB free: 38912 kB; InnoDB free: 38912 kB; InnoDB free: 3' AUTO_INCREMENT=;

ALTER TABLE `details_options`
  
ADD CONSTRAINT `details_options_keysFOREIGN KEY (`detail_cod`) REFERENCES `details` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
Grazie