tags:

views:

90

answers:

1

I have got a problem with two tables:

 CREATE TABLE IF NOT EXISTS `addresses` ( 
  `adr_id` int(11) NOT NULL auto_increment, 
  `per_id` int(11) NOT NULL, 
  `adr_street` varchar(50) NOT NULL, 
  `adr_houseno` int(11) default NULL, 
  `adr_housenoadd` varchar(10) default NULL, 
  `adr_postalcode` varchar(25) NOT NULL, 
  `adr_city` varchar(20) NOT NULL, 
  `adr_type` varchar(45) default NULL, 
  `cnt_id` int(11) NOT NULL, 
  `adr_date` date default NULL, 
  `sys-mut-dt` timestamp NULL default NULL, 
  `sys-mut-user` varchar(20) default NULL, 
  `sys-mut-id` int(11) NOT NULL default '0', 
  PRIMARY KEY  (`adr_id`), 
  KEY `per_id` (`per_id`), 
  KEY `cnt_id` (`cnt_id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; 
-- 
-- RELATIES VOOR TABEL `addresses`: 
--   `cnt_id` 
--       `countries` -> `cnt_id` 
--   `per_id` 
--       `persons` -> `per_id` 
-- 

CREATE TABLE `events` ( 
  `evt_id` int(11) NOT NULL auto_increment, 
  `evt_name` varchar(50) NOT NULL, 
  `evt_description` varchar(100) default NULL, 
  `evt_startdate` date NOT NULL, 
  `evt_enddate` date default NULL, 
  `evt_starttime` time default NULL, 
  `evt_endtime` time default NULL, 
  `evt_amtpersons` int(11) default NULL, 
  `sts_id` int(11) NOT NULL, 
  `adr_id` int(11) default NULL, 
  `evt_amtPersonsSubs` tinyint(4) NOT NULL default '0', 
  `evt_photo` varchar(50) default NULL, 
  `sys-mut-dt` timestamp NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, 
  `sys-mut-user` varchar(20) default NULL, 
  `sys-mut-id` int(11) NOT NULL default '0', 
  PRIMARY KEY  (`evt_id`), 
  KEY `sts_id` (`sts_id`), 
  KEY `adr_id` (`adr_id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

The problem is, when i try to delete a record from address table I get the following error

DELETE
FROM    addresses
WHERE   per_id = 45

1451 - Cannot delete or update a parent row: a foreign key constraint fails (`site/events`, CONSTRAINT `adr_id` FOREIGN KEY (`adr_id`) REFERENCES `addresses` (`adr_id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ;

The weird thing is that there is no record with the same per_id or adr_id in the events table.

So what's going on over here?

How Can I solve this? ;-)

/* I think it means "How can I solve this?" */
+2  A: 

It may sound stupid, but are you absolutely sure there are no child rows?

Could you please run this:

SELECT  e.*
FROM    addresses a
JOIN    events e
ON      e.adr_id = a.adr_id
WHERE   a.per_id = 45
Quassnoi