I have created a table member_history_logs.
CREATE TABLE `member_history_logs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`element_id` int(11) NOT NULL,
`status` varchar(1) DEFAULT NULL,
`start_date` datetime NOT NULL,
`end_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `status` (`status`),
KEY `element_id` (`element_id`)
) ENGINE=InnoDB AUTO_INCREMENT=134 DEFAULT CHARSET=utf8;
There is another table named members consisting of
'id', 'int(11)', 'NO', 'PRI', NULL, 'auto_increment'
'description', 'varchar(100)', 'NO', '', NULL, ''
'short_name', 'varchar(1)', 'YES', '', NULL, ''
I want to perform an alter table
alter table member_history_logs add foreign key (element_id) references members (id);
I am getting the following error:
Error Code:1452 cannot add or update a child row a foreign key constraint fails mysql
Please correct me. Where am I going wrong.