List:General Discussion« Previous MessageNext Message »
From:<jc Date:May 14 2010 5:53pm
Subject:RE: Can't create foreign key
View as plain text  
Interesting. Thanks for that tip on showing the INNODB STATUS.  It turned up
the error:

A foreign key constraint of name `cc/fk_lessons` already exists.

...which tells me that a foreign key name cannot already be in use even if
on a different table (at least that's what it appears to be saying).  I
named the foreign key something totally different than anything else in the
database, and it worked.  So, I guess foreign keys must have unique names
like tables do.


-----Original Message-----
From: Gavin Towey [mailto:gtowey@stripped] 
Sent: Friday, May 14, 2010 1:45 PM
To: jc@stripped; mysql@stripped
Subject: RE: Can't create foreign key

Perror 121 says:
OS error code 121:  Remote I/O error

Which I'm not too sure why an ALTER to add an constraint would give that

Normally though, foreign key errors are shown in the SHOW ENGINE INNODB
STATUS \G output, look for more details there.

Gavin Towey

-----Original Message-----
From: jc@stripped [mailto:jc@stripped]
Sent: Friday, May 14, 2010 10:18 AM
To: mysql@stripped
Subject: Can't create foreign key

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` )



, 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?



This message contains confidential information and is intended only for the
individual named.  If you are not the named addressee, you are notified that
reviewing, disseminating, disclosing, copying or distributing this e-mail is
strictly prohibited.  Please notify the sender immediately by e-mail if you
have received this e-mail by mistake and delete this e-mail from your
system. E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed, arrive late
or incomplete, or contain viruses. The sender therefore does not accept
liability for any loss or damage caused by viruses or errors or omissions in
the contents of this message, which arise as a result of e-mail
transmission. [FriendFinder Networks, Inc., 220 Humbolt court, Sunnyvale, CA
94089, USA,

MySQL General Mailing List
For list archives:
To unsubscribe:

Can't create foreign keyjc14 May
  • RE: Can't create foreign keyGavin Towey14 May
    • RE: Can't create foreign keyjc14 May
  • Re: Can't create foreign keyCarsten Pedersen14 May
    • RE: Can't create foreign keyjc14 May
      • Re: Can't create foreign keyPrabhat Kumar14 May