I am trying to create a table for a many to many
relationship in mySQL
. This is the sql
for it:
CREATE TABLE `directoryprogrammetags` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`directoryprogramme_id` INT(11) NOT NULL,
`tag_id` INT(11) NOT NULL,
`description` TEXT,
`created` DATETIME DEFAULT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`directoryprogramme_id`) REFERENCES directoryprogramme(id),
FOREIGN KEY (`tag_id`) REFERENCES tag(id)
) ENGINE=INNODB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8;
But I am getting this error:
Error Code: 1005
Can't create table 'mytestdatabase.directoryprogrammetags' (errno: 150)
The tables that the foreign keys reference are:
CREATE TABLE `directoryprogramme` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) NOT NULL,
`description` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1200 DEFAULT CHARSET=utf8
and
CREATE TABLE `tag` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(200) DEFAULT NULL,
`description` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8
I read somewhere that it could be to do with an inconsistency with the foreign key but I am not sure. Can anyone help me out on this one?