powerpants Posted February 23, 2009 Share Posted February 23, 2009 Hi everyone, I'm setting up my first MySQL database, but none of my foreign keys seem to be getting configured correctly according to my SHOW CREATE TABLE output. For example, I have a table called image_person which has two attributes that should be foreign keyed to two different tables which hold the image_id's and person_id's. I set up the table using the following command: CREATE TABLE image_person( image_id int NOT NULL, person_id int NOT NULL, FOREIGN KEY (image_id) REFERENCES image(image_id), FOREIGN KEY (person_id) REFERENCES person(person_id) ); But, when I SHOW CREATE TABLE image_person, I get...... | image_person | CREATE TABLE `image_person` ( `image_id` int(11) NOT NULL, `person_id` int(11) NOT NULL, KEY `image_id` (`image_id`), KEY `person_id` (`person_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 | Shouldn't I see the foreign key information? What am I doing wrong? I'm running MySQL 5.0.45 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/146545-solved-newbie-help-foreign-key-not-taking/ Share on other sites More sharing options...
fenway Posted February 24, 2009 Share Posted February 24, 2009 No FKs with MyISAM engine... you need InnoDB. Quote Link to comment https://forums.phpfreaks.com/topic/146545-solved-newbie-help-foreign-key-not-taking/#findComment-770165 Share on other sites More sharing options...
powerpants Posted February 25, 2009 Author Share Posted February 25, 2009 Ok, thanks. I looked into InnoDB, and here's my new query: CREATE TABLE image_person( image_id int NOT NULL, person_id int NOT NULL, FOREIGN KEY (image_id) REFERENCES image(image_id), FOREIGN KEY (person_id) REFERENCES person(person_id) ) ENGINE=INNODB; And, here's the error I get: ERROR 1005 (HY000): Can't create table './davidland/image_person.frm' (errno: 150) From what I've been reading, InnoDB and not-InnoDB tables are freely mixable in databases, right? Or could this problem be that I'm trying to foreign key to a table which is not InnoDB? Thanks for your reply! Quote Link to comment https://forums.phpfreaks.com/topic/146545-solved-newbie-help-foreign-key-not-taking/#findComment-770770 Share on other sites More sharing options...
fenway Posted February 25, 2009 Share Posted February 25, 2009 You may want to have a look here... they can't be mixed "freely". Quote Link to comment https://forums.phpfreaks.com/topic/146545-solved-newbie-help-foreign-key-not-taking/#findComment-770831 Share on other sites More sharing options...
powerpants Posted February 25, 2009 Author Share Posted February 25, 2009 That's just what I needed. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/146545-solved-newbie-help-foreign-key-not-taking/#findComment-770861 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.