Hi, I don't know much about the foreign key syntax, but I would think it
should reference a field in a different table.  If I'm wrong, I'm sorry.
:-)

Bob


-----Original Message-----
From: Mofeed Shahin [mailto:[EMAIL PROTECTED]
Sent: Sunday, December 14, 2003 9:56 PM
To: Paul DuBois; [EMAIL PROTECTED]
Subject: Re: foreign keys.


On Mon, 15 Dec 2003 12:42 pm, Paul DuBois wrote:
> At 11:09 +1030 12/15/03, Mofeed Shahin wrote:
> >I'm trying to create a bunch of tables in MySQL. I'm having problems
> > creating the following table :
> >
> >CREATE TABLE foo(
> >     ID INT PRIMARY KEY,
> >     note VARCHAR(50),
> >     FOO_ID INT,
> >     FOREIGN KEY (FOO_ID) REFERENCES foo(ID)
> >) TYPE=INNODB;
> >
> >The error I get is the following :
> >ERROR 1005: Can't create table './moftest/foo.frm' (errno: 150)
> >
> >I found out that errno 150 means that it didn't like the Foreign key
> >constraint.
> >
> >Does MySQL not support this type of Foreign Key constraint ?
>
> If does.  However, a foreign key must be indexed, and you have declared
> no index on FOO_ID.  Try this:
>
> CREATE TABLE foo(
>      ID INT PRIMARY KEY,
>      note VARCHAR(50),
>      FOO_ID INT,
>      INDEX (FOO_ID),
>      FOREIGN KEY (FOO_ID) REFERENCES foo(ID)
> ) TYPE=INNODB;

Thanks, but I just did, and I got the same error message.

Mof.


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to