I'm building a question and answer site and for linking the user accounts to the questions I want to have the username from the login table be a foreign key of the questions table so when a user asks a question it must be linked to his or her username. Can I not have foreign key's that are varchar datatype? Or must the foreign key be only a primary key of another table? The error I'm getting says 'Key column "'username' doesn't exist in table" . What am I doing wrong?
create table login (user_id int NOT NULL AUTO_INCREMENT, username
varchar (100), password varchar (100), primary key (user_id));
create table questions (q_id int not null auto_increment, question
varchar (100), primary key (q_id), foreign key (username) references
login (username));