Jump to content

[SOLVED] Newbie Help - Foreign Key Not 'Taking'


powerpants

Recommended Posts

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!

Link to comment
Share on other sites

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!

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.