If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Primary Key is Foreign Key Error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-18-08, 14:57
ajr87 ajr87 is offline
Registered User
 
Join Date: Nov 2006
Posts: 8
Primary Key is Foreign Key Error

I have made this table:
CREATE TABLE `Users` (
`userID` varchar(10) NOT NULL,
`fName` varchar(25) NOT NULL,
`lName` varchar(30) NOT NULL,
`emailAddress` varchar(100) NOT NULL,
PRIMARY KEY (`userID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

And then this:
CREATE TABLE `Courses` (
`courseID` varchar(10) NOT NULL,
`courseName` varchar(30) NOT NULL,
PRIMARY KEY (`courseID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Now I want to create this:
CREATE TABLE `StudentCourses` (
`studentID` varchar(10) NOT NULL,
`courseID` varchar(10) NOT NULL,
PRIMARY KEY (`studentID`,`courseID`),
INDEX (`studentID`, `courseID`),
FOREIGN KEY (`studentID`) REFERENCES `Users` (`userID`) ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY (`courseID`) REFERENCES `Courses` (`coursesID`) ON UPDATE CASCADE ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Which is supposed to be a table where both fields are needed to identify a row and the values of these two fields come from the two tables given earlier.

But I get "Error code 1005, SQL state HY000: Can't create table '.\thedatabase\studentcourses.frm' (errno: 150)"

I'm sure this can be done. Can anyone help?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On