is it possible to define two column as Foreign Key(both in same table) in the table
need to define two column( that both related to the same table ) as one Foreign key constraint but I receive (errno: 150 "Foreign key constraint is incorrectly formed") my engin is innodb thanks in advance for any help
CREATE TABLE `reports` ( `SID` VARCHAR(100) NOT NULL, `Type` INT(11) NULL DEFAULT NULL, `Title` VARCHAR(255) NULL DEFAULT NULL, /*and etc..*/ `SDate` DATETIME NOT NULL, PRIMARY KEY (`SID`, `SDate`) );
CREATE TABLE `rprtcontent` ( `ID` INT(11) NOT NULL AUTO_INCREMENT, `SID` VARCHAR(100) NOT NULL, `Findings` LONGTEXT NULL DEFAULT NULL, `SDate` DATETIME NOT NULL, `ContentDate` DATETIME NULL DEFAULT NULL, PRIMARY KEY (`ID`), INDEX `IX_RptContent_Reports`(`SID`,`SDate`), CONSTRAINT `FK_ReportContent_Reports` FOREIGN KEY(`SID`,`SDate`) REFERENCES `reports`(`SID`,`SDate`) ON UPDATE NO ACTION ON DELETE NO ACTION )
Answer Answered by Ian Gilfillan in this comment.
The syntax you have copied above is valid in both MariaDB 10.3.11 and MariaDB 5.5.56, can you give more details?