layman Posted April 1, 2011 Share Posted April 1, 2011 Hello, Could anyone tell me what is wrong with this code? Thanks for any help! The error I am getting is: #1072 - Key column 'Login_id' doesn't exist in table Server version: 5.1.41 I have created already the Login_detail table I am referencing, so that one can not be the problem. Or can be??? CREATE TABLE IF NOT EXISTS CUSTOMERS ( Customer_id int(4) not null auto_increment, Customer_name varchar(80) not null default '', Customer_address1 varchar(50) not null default '', Customer_address2 varchar(50) not null default '', Customer_town varchar(50) not null default '', Customer_postcode varchar(9) not null default '', Customer_county varchar(30) not null default '', Customer_country varchar(30) not null default '', Customer_phoneno int(14) not null, Customer_email varchar(50) not null default '', key Customer_id (Customer_id), PRIMARY KEY (Customer_id), FOREIGN KEY (Login_id) references login_detail(Login_id) on update cascade on delete cascade ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Quote Link to comment https://forums.phpfreaks.com/topic/232422-could-anyone-tell-me-what-is-wrong-with-this-create-table-code/ Share on other sites More sharing options...
kickstart Posted April 1, 2011 Share Posted April 1, 2011 Hi The table you are creating doesn't have a column called login_id. You need to define which column in the table you are creating refers to the column in the other table. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/232422-could-anyone-tell-me-what-is-wrong-with-this-create-table-code/#findComment-1195568 Share on other sites More sharing options...
layman Posted April 1, 2011 Author Share Posted April 1, 2011 Hi I don`t understand. How should I make a foreign key if not like this? Quote Link to comment https://forums.phpfreaks.com/topic/232422-could-anyone-tell-me-what-is-wrong-with-this-create-table-code/#findComment-1195570 Share on other sites More sharing options...
kickstart Posted April 1, 2011 Share Posted April 1, 2011 Hi The line:- FOREIGN KEY (Login_id) references login_detail(Login_id) on update cascade on delete cascade the bit in bold refers to a column on the table you are creating while the bit underlined refers to a column on another table. The table you are creating doesn't have a column called Login_id though. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/232422-could-anyone-tell-me-what-is-wrong-with-this-create-table-code/#findComment-1195577 Share on other sites More sharing options...
layman Posted April 1, 2011 Author Share Posted April 1, 2011 Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/232422-could-anyone-tell-me-what-is-wrong-with-this-create-table-code/#findComment-1195579 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.