mysql - Cannot add foreign key constraint -


i have created database "webportal". , "user" table script

drop table if exists `user`; create table `user` (   `id` int(11) not null auto_increment,   `username` varchar(255) default null,   `password` varchar(255) default null,   `firstname` varchar(255) default null,   `lastname` varchar(255) default null,   `dateregistered` date default null,   `skypeid` int(11)  default null,   primary key (`id`) ) engine=innodb auto_increment=4 default charset=utf8; 

and 1 "catalog" table script.

drop table if exists `catalog`; create table catalog(   `id` int(11) not null auto_increment,   `user_id` int(11) not null,   `link`  varchar(100) not null,   `comment`  varchar(100) not null,   `inserdate` date default null,   `content` longblob not null,   primary key (`id`),   constraint `fk_catalog` foreign key (`user_id`) references `user` (`id`) on delete cascade on update cascade ) engine=innodb default charset=utf8; 

and when try execute second script in command line, error...

error 1215 (hy000): cannot add foreign key constraint. wrong code?

it seems using old version of mysql, can add index clause foreign key field fix problem:

drop table if exists `catalog`; create table `catalog`(   `id` int(11) not null auto_increment,   `user_id` int(11) not null,   `link`  varchar(100) not null,   `comment`  varchar(100) not null,   `inserdate` date default null,   `content` longblob not null,   primary key (`id`),   index (`user_id`),   constraint `fk_catalog` foreign key (`user_id`) references `user` (`id`) on delete cascade on update cascade ) engine=innodb default charset=utf8; 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -