Microsoft
Software
Hardware
Network
Question : foreign key constraint error question
I have the following tables
CREATE TABLE `w_document_flat` (
`Accession_No` varchar(7) NOT NULL,
`Pub_Abbreviation` varchar(25) NOT NULL,
PRIMARY KEY (`Accession_No`)
) ENGINE=MyISAM
CREATE TABLE `descriptors` (
`descriptor_id` int(11) NOT NULL auto_increment,
`descriptor_name` varchar(500) NOT NULL,
PRIMARY KEY (`descriptor_id`)
) ENGINE=InnoDB
CREATE TABLE `w_descriptors` (
`descriptor_id` int(11) NOT NULL,
`Accession_No` varchar(7) NOT NULL,
PRIMARY KEY (`descriptor_id`,`Accessio
n_No`),
KEY `Accession_No` (`Accession_No`),
KEY `descriptor_id` (`descriptor_id`),
CONSTRAINT `Accession_No` FOREIGN KEY (`Accession_No`) REFERENCES `w_document_flat` (`Accession_No`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `descriptor_id` FOREIGN KEY (`descriptor_id`) REFERENCES `descriptors` (`descriptor_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB
When I try and do an insert into the
insert into w_descriptors (descriptor_id, Accession_No) values ("0000001", 1);
I get the following message:
Error Code: 1452
Cannot add or update a child row: a foreign key constraint fails (`w/w_descriptors`, CONSTRAINT `Accession_No` FOREIGN KEY (`Accession_No`) REFERENCES `w_document_flat` (`Accession_No`) ON DELETE NO ACTION ON UPDATE NO ACTION)
I am really confused. Is it because the w_document_flat table is MyISAM?
Answer : foreign key constraint error question
Yes, "Both tables must be InnoDB tables and they must not be TEMPORARY tables. "
http://dev.mysql.com/doc/r
efman/5.1/
en/innodb-
foreign-ke
y-
constrai
nts.html
I ran into the same problem recently.
Random Solutions
look up table value with sql
Change key default value by script
How to set Public Folder "Retention" so that if a public folder is accidently deleted it can easily be recovered through Outlook or PFDAVadmin
Is there any way to limit what the users see in shared calendars in Exchange 2003 / Exchange 2007?
Using VLookup for Data Validation
WebService Client problem
web design vs dev
How to delete Clonezilla Images
Migrate SBS 2003 to Server 2008 R2
Cannot Replicate FREEBUSY from Exchange 2003 to Exchange 2010 - EVENT 14029, 4003,