I am trying to add a new table to MySQL but I am getting the cannot add foreign key constraint error.
The SQL i am trying to execute is :
CREATE TABLE `local_news` (
`local_news_id` int(11) NOT NULL AUTO_INCREMENT,
`org_id` int(11) NOT NULL,
`org_contact_id` int(11) NOT NULL,
`title` varchar(255) NOT NULL COMMENT 'title',
`message` text DEFAULT NULL,
`published` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0-draft, 1-published',
`create_time` datetime DEFAULT NULL,
PRIMARY KEY (`local_news_id`),
KEY `FK_Reference_56` (`org_id`),
KEY `FK_Reference_57` (`org_contact_id`),
CONSTRAINT `FK_Reference_56` FOREIGN KEY (`org_id`) REFERENCES `organization` (`org_id`),
CONSTRAINT `FK_Reference_57` FOREIGN KEY (`org_contact_id`) REFERENCES `org_contacts` (`contact_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='All local site content in the news tab';
My 'organization' table has 'org_id' as int(11) and set as its primary key.
My 'org_contacts' table has 'contact_id' as int(11) and set as its primary key.
The complete error I found (while using show engine innodb status) is:
------------------------ LATEST FOREIGN KEY ERROR ------------------------ 2017-02-15 22:28:27 0x2b64 Error in foreign key constraint of table giveaday/local_news:
FOREIGN KEY (`org_id`) REFERENCES `organization` (`org_id`), CONSTRAINT `FK_Reference_57` FOREIGN KEY (`org_contact_id`) REFERENCES `org_contacts` (`contact_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='All local site content in the news tab': Cannot resolve table name close to: (`org_id`), CONSTRAINT `FK_Reference_57` FOREIGN KEY (`org_contact_id`) REFERENCES `org_contacts` (`contact_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='All local site content in the news tab'
However the table "organization" does exist and is exactly called "organization", no typos made.