Newbie Q - Foreign Key issue
Posted by:
Shaun Dean
Date: August 21, 2008 04:17AM
Let me preface all of this with the fact that I am completely new to MySQL - everything I know about it has come over the past 5 days or so. Lots of reading, lots of downloading, lots of hair pulling... you get the idea.
So I'm working on a database right now - 1 table [items] is the parent table for two others: [recipes] and [merchants]. I can get all of the data stuffed into the [items] table, and I can get the non-referenced data put into the other two. The problem comes when I try and set up the foreign keys in the [recipes] and [merchants] tables - I get the dreaded #1452 error. I'm working in Navicat as well, so I don't deal with the straight code - I know enough to know that I don't know THAT much. Both tables are also in InnoDB format, made sure of that before I posted anything.
Lets see... things that might be helpful to know:
CREATE TABLE items (
`items_id' varchar(255) NOT NULL,
`item_title` varchar(255) NOT NULL,
`itemtype_1` varchar(255) NOT NULL,
`itemtype_2' varchar(255),
PRIMARY KEY (`items_id`)
)
CREATE TABLE recipes (
`recipes_id` varchar(255) NOT NULL,
`skill_level` int(5) NOT NULL,
`ing amt 1` int(5) NOT NULL,
`item_title` varchar(255) NOT NULL,
`itemtype_1` varchar(255) NOT NULL,
`itemtype_2` varchar(255),
PRIMARY KEY (`recipes_id`)
)
Those, I've seen often enough to be able to type out from memory, but as far as the foreign key stuff, I let the program handle that. I'm trying to link `item_title`, `itemtype_1` and `itemtype_2` into the appropriate fields in the [items] table... but nothing I've yet done seems to be working. Help?