It want to create 2 tables. 1 table has created but another one is giving error in creating! Note: Both table are Innodb
journal:
---------
jr_date --> primary
entry_no --> primary
description
DDL:
CREATE TABLE `journal` (
`jr_date` date NOT NULL,
`entry_no` smallint(6) NOT NULL,
`description` varchar(100) DEFAULT NULL,
PRIMARY KEY (`jr_date`,`entry_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Now want to create following table but getting error! Why?
ERROR 1215: Cannot add foreign key constraint
SQL Statement:
CREATE TABLE `accounting`.`journal_details` (
`jr_date` DATE NULL,
`entry_no` SMALLINT NULL,
`serial` TINYINT NULL,
INDEX `fk_journal_details_jr_date_idx` (`jr_date` ASC),
INDEX `fk_journal_details_entry_no_idx` (`entry_no` ASC),
CONSTRAINT `fk_journal_details_jr_date`
FOREIGN KEY (`jr_date`)
REFERENCES `accounting`.`journal` (`jr_date`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_journal_details_entry_no`
FOREIGN KEY (`entry_no`)
REFERENCES `accounting`.`journal` (`entry_no`)
ON DELETE CASCADE
ON UPDATE CASCADE)
I could not understand why foreign keys are not created?