Can"t create foreign key

Can"t create foreign key

am 14.05.2010 19:17:40 von JC

------=_NextPart_000_00A9_01CAF367.D4D74820
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

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


------=_NextPart_000_00A9_01CAF367.D4D74820--

RE: Can"t create foreign key

am 14.05.2010 19:44:49 von Gavin Towey

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 er=
ror.

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

Regards,
Gavin Towey

-----Original Message-----
From: jc@msdlg.com [mailto:jc@msdlg.com]
Sent: Friday, May 14, 2010 10:18 AM
To: mysql@lists.mysql.com
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` )

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


This message contains confidential information and is intended only for the=
individual named. If you are not the named addressee, you are notified th=
at reviewing, disseminating, disclosing, copying or distributing this e-mai=
l is strictly prohibited. Please notify the sender immediately by e-mail i=
f 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-fre=
e as information could be intercepted, corrupted, lost, destroyed, arrive l=
ate 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 transmis=
sion. [FriendFinder Networks, Inc., 220 Humbolt court, Sunnyvale, CA 94089,=
USA, FriendFinder.com

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg

Re: Can"t create foreign key

am 14.05.2010 19:48:35 von Carsten Pedersen

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

jc@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=gcdmg-mysql-2@m.gmane.org

RE: Can"t create foreign key

am 14.05.2010 19:53:41 von JC

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.

Thanks,
Jesse

-----Original Message-----
From: Gavin Towey [mailto:gtowey@ffn.com]
Sent: Friday, May 14, 2010 1:45 PM
To: jc@msdlg.com; mysql@lists.mysql.com
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
error.

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

Regards,
Gavin Towey

-----Original Message-----
From: jc@msdlg.com [mailto:jc@msdlg.com]
Sent: Friday, May 14, 2010 10:18 AM
To: mysql@lists.mysql.com
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` )

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


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, FriendFinder.com

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=jc@msdlg.com




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

RE: Can"t create foreign key

am 14.05.2010 20:03:00 von JC

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:carsten@bitbybit.dk]
Sent: Friday, May 14, 2010 1:49 PM
To: jc@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

jc@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=jc@msdlg.com




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: Can"t create foreign key

am 14.05.2010 20:46:07 von prabhat kumar

--00163630fa2dbdee2c04869249af
Content-Type: text/plain; charset=ISO-8859-1

I have faced the same issue in past. *
key name must be a unique*.

On Fri, May 14, 2010 at 11:33 PM, 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:carsten@bitbybit.dk]
> Sent: Friday, May 14, 2010 1:49 PM
> To: jc@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
>
> jc@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=jc@msdlg.com
>
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=aim.prabhat@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

--00163630fa2dbdee2c04869249af--