I have faced the same issue in past. * key name must be a unique*. On Fri, May 14, 2010 at 11:33 PM, <j...@msdlg.com> wrote:
> Nope, that wasn't the problem. I wasn't aware that the foreign key name > must be unique. So, if you have a foreign key named "fk_lesson", that same > name cannot exist already, even if on a different table. I named the > foreign key something completely different and that solved the problem. > > Jesse > > -----Original Message----- > From: Carsten Pedersen [mailto:cars...@bitbybit.dk] > Sent: Friday, May 14, 2010 1:49 PM > To: j...@msdlg.com > Cc: mysql@lists.mysql.com > Subject: Re: Can't create foreign key > > Haven't done this in a while, but I'm guessing that you can't create > both a constraint and an index with the same name? > > Type mismatch will in my experience most often generate an errno 150. > > / Carsten > > j...@msdlg.com skrev: > > I'm trying to create a foreign key by executing the following statement: > > > > ALTER TABLE `cc`.`takenlessons` > > > > ADD CONSTRAINT `fk_lessons` > > > > FOREIGN KEY (`LessonID` ) > > > > REFERENCES `cc`.`lessons` (`id` ) > > > > ON DELETE CASCADE > > > > ON UPDATE NO ACTION > > > > , ADD INDEX `fk_lessons` (`LessonID` ASC) ; > > > > > > > > I'm using the RC of MySQL workbench to do this. When I execute this > > statement, I get the following error: > > > > Error Code: 1005 > > > > Can't create table 'cc.#sql-115c_61' (errno: 121)) > > > > > > > > In the past when I got a similar error, it was because the fields didn't > > match exactly. For instance, one may be Int(10) and one Int(11), or one > may > > be Unsigned, and the other not. But, in this case, both match exactly. > > What other reasons are there for a foreign key creation to fail like > that? > > > > > > > > Thanks, > > > > Jesse > > > > > > > > !DSPAM:451,4bed85fe818443309765824! > > > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: http://lists.mysql.com/mysql?unsub...@msdlg.com > > > > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: > http://lists.mysql.com/mysql?unsub=aim.prab...@gmail.com > > -- Best Regards, Prabhat Kumar MySQL DBA Datavail-India Mumbai Mobile : 91-9987681929 www.datavail.com My Blog: http://adminlinux.blogspot.com My LinkedIn: http://www.linkedin.com/in/profileprabhat