mysql error code 1022 duplicate key in table -
i searched through prior posts didn't quite find answer, here goes ...
i have table
create table `leags` ( `lid` int(10) not null auto_increment, `lname` varchar(255) not null, `description` varchar(255) default null, `links` varchar(255) default null, `cid` int(10) not null, primary key (`lid`), key `index2` (`lid`,`lname`), key `index3` (`lid`,`lname`,`cid`), key `cid_idx` (`cid`), constraint `cid` foreign key (`cid`) references `cats` (`cid`) ) engine=innodb auto_increment=2 default charset=utf8 comment='leagues'$$
i have table has above pk foreign key.
create table `tams` ( `tid` int(10) not null , `tname` varchar(255) not null , `lid` int(10) null , `url` text null , primary key (`tid`) , index `index2` (`tid` asc, `tname` asc) , index `index3` (`tid` asc, `tname` asc, `lid` asc) , index `lid_idx` (`lid` asc) , constraint `lid` foreign key (`lid` ) references leags` (`lid` ) on delete no action on update no action) engine = innodb
the creation of table works fine, run problem creating below table.
create table if not exists spsched ( `spscid` int(10) not null auto_increment , `startdate` date not null , `enddate` date null , `starttime` time not null , `endtime` time null , `htid` int(10) null , `type` varchar(45) null , `atid` int(10) null , `leagid` int(10) null , primary key (`spscid`) , unique index `spscid_unique` (`spscid` asc) , index `htid_idx` (`htid` asc) , index `atid_idx` (`atid` asc) , index `lid_idx` (`leagid` asc) , constraint `tid` foreign key (`htid` ) references tams (`tid` ) on delete no action on update no action, constraint `atid` foreign key (`atid` ) references tams` (`tid` ) on delete no action on update no action, constraint `lid` foreign key (`leagid` ) references leags (`lid` ) on delete no action on update no action) engine = innodb
if remove lid fk , constraint above sql, table creates fine. can't figure out duplicate key in here. appreciated. thanks.
lid
have constraint name in table tams lid
.
i suspect system not case sensitive.
http://richardfearn.wordpress.com/2007/03/12/case-insensitive-constraint-names-in-mysql/
internally, innodb stores foreign key constraint names case-insensitive, database name prepended. although onedatabase.b_ibfk_1 treated different anotherdatabase.b_ibfk_1, photos.b_ibfk_1 , photos.b_ibfk_1 treated same.
just pick name key.
Comments
Post a Comment