Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to create a references to foreign table. but i'm getting the following error:

query:

CREATE TABLE category_ids (id INT, post_id INT,
                    INDEX par_ind (post_id),
                    FOREIGN KEY (post_id) REFERENCES post(id)
                      ON DELETE CASCADE
) ENGINE=INNODB;

SHOW ENGINE INNODB STATUSG:

------------------------
LATEST FOREIGN KEY ERROR
------------------------
2013-08-23 00:11:06 7f6f49e7b700 Error in foreign key constraint of table fun/category_ids:
FOREIGN KEY (post_id) REFERENCES post(id)
                      ON DELETE CASCADE
) ENGINE=INNODB:
Cannot resolve table name close to:
(id)
                      ON DELETE CASCADE
) ENGINE=INNODB

posts table structure

    mysql> describe post;
    +-------------+-----------------------+------+-----+---------------------+----------------+
    | Field       | Type                  | Null | Key | Default             | Extra          |
    +-------------+-----------------------+------+-----+---------------------+----------------+
    | id          | int(11)               | NO   | PRI | NULL                | auto_increment |
...
    +-------------+-----------------------+------+-----+---------------------+----------------+
    22 rows in set (0.00 sec)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
754 views
Welcome To Ask or Share your Answers For Others

1 Answer

Only InnoDB supports Foreign keys, MyISAM doesn't. Even if it would, you cannot create relations between tables of different type.

Therefore you need to convert the table post into InnoDB. ALTER TABLE post ENGINE = InnoDB;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...