I'm working on a database so that students can swap classes.
user
being the student.
class
being the classes.
has
being the classes that the student currently has.
wants
being the classes that that the student doesn't have but wants.
CREATE TABLE Class
(
ClassName varchar(255),
Professor_Name varchar(255),
Start_Time varchar(10),
End_Time varchar(10),
Course_Number varchar(20),
Section_Number varchar(20),
Days varchar(10),
PRIMARY KEY(Course_Number,Section_Number));
CREATE TABLE User
(
Email VARCHAR(255),
first_name VARCHAR(255),
last_name VARCHAR(255),
password1 VARCHAR(255),
PRIMARY KEY (Email)
);
CREATE TABLE Has
(
Email VARCHAR(255),
Course_Number VARCHAR(20),
Section_Number VARCHAR(20),
PRIMARY KEY (Email, Course_Number, Section_Number),
FOREIGN KEY (Email) REFERENCES User (Email),
FOREIGN KEY (Course_Number, Section_Number) REFERENCES Class (Course_Number, Section_Number)
);
CREATE TABLE Wants
(
Email VARCHAR(255),
Course_Number VARCHAR(20),
Section_Number VARCHAR(20),
PRIMARY KEY (Email, Course_Number, Section_Number),
FOREIGN KEY (Email) REFERENCES User (Email),
FOREIGN KEY (Course_Number, Section_Number) REFERENCES Class (Course_Number, Section_Number)
);
and put classes into the class table and users into the user table and now im trying to add classes that the students "have" and classes that the students may "want"
I wrote the following query to add a class that a student has with the students email, class course number and class section number
INSERT INTO Has
VALUES ('johnsmith@school.edu', 'CDA 3103', 'U01-C');
but for some reason im getting the following error
Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (
spr17_fkais001
.SEHAS
, CONSTRAINTSEHAS_ibfk_1
FOREIGN KEY (SEUSER
(
does anybody know why this is? and how I can start adding classes to wants and has?