I have spent a good 3 hours searching for the answer to my problem (on here and google) and I cannot understand why I am getting this error after I try to add the "events" table.
Two tables:
CREATE TABLE user (
id INT NOT NULL AUTO_INCREMENT,
u_name VARCHAR(32) NOT NULL,
u_pass VARCHAR(32) NOT NULL,
sub_status INT(3) NOT NULL,
f_name VARCHAR(32),
l_name VARCHAR(32),
email VARCHAR(32),
PRIMARY KEY(id, u_name, email)
) ENGINE=InnoDB;
CREATE TABLE events (
u_name VARCHAR(32) NOT NULL,
event_name VARCHAR(32),
event_date VARCHAR(32),
comment VARCHAR(255),
PRIMARY KEY(u_name, event_name),
FOREIGN KEY(u_name) REFERENCES user(u_name)
ON UPDATE CASCADE
ON DELETE CASCADE
) ENGINE=InnoDB;
As far as I can see, there are no spelling errors, u_name is the exact same type between tables and it is a primary key in both tables.
mysql version is 5.6
Help is much appreciated and I thank you in advance. Let me know if there is any else I need to include.
EDIT: Turns out my queries do work, but on a different version of sql/mysql. jemz's answer works as well for a different version of sql.