bionic25 Posted December 10, 2009 Share Posted December 10, 2009 hey guys, i am having problems with foreign keys. my code below all executes fine in mysql, returning data for all the tables, except for 'activities' which is usinf foreign keys to reference the correctly functioning other tables. Can anyone see what is wrong because after looking at other examples for hours i cant figure it out! CREATE TABLE modules ( module_id INT AUTO_INCREMENT, deptcode VARCHAR(10), module VARCHAR(10), title VARCHAR(255), Primary Key(module_id) ); CREATE TABLE lecturers ( lecturer_id INT AUTO_INCREMENT, fname VARCHAR(50), lname VARCHAR(50), Primary Key(lecturer_id) ); CREATE TABLE groups ( group_id INT AUTO_INCREMENT, groupName VARCHAR(12), Primary Key(group_id) ); INSERT INTO modules (deptcode, module, title) SELECT deptcode, module1, title1 FROM tempHolder; INSERT INTO lecturers (fname, lname) SELECT SUBSTRING_INDEX(lecturer1, ', ', -1), SUBSTRING_INDEX(lecturer1, ', ', 1) FROM tempHolder; INSERT INTO groups (groupName) SELECT group1 FROM tempHolder; CREATE TABLE activities ( activity_id INT AUTO_INCREMENT, module_id integer, lecturer_id integer, group_id integer, Primary Key (activity_id), Foreign Key (module_id) references modules(module_id), Foreign Key (lecturer_id) references lecturers(lecturer_id), Foreign Key (group_id) references groups(group_id) ); //For debugging, output all results select * from modules where module_id=3; select * from lecturers where lecturer_id=3; select * from groups where group_id=3; select * from activities; thanks in advance for any help Quote Link to comment https://forums.phpfreaks.com/topic/184702-foreign-keys-problem/ Share on other sites More sharing options...
fenway Posted December 14, 2009 Share Posted December 14, 2009 What's the error? Quote Link to comment https://forums.phpfreaks.com/topic/184702-foreign-keys-problem/#findComment-977211 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.