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;

--
Paul DuBois, Senior Technical Writer
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

Are you MySQL certified? http://www.mysql.com/certification/


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



Reply via email to