Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So, when I create this database I am getting the error 1215 cannot add foreign key restraint. Why am I getting this? create database if

So, when I create this database I am getting the error 1215 cannot add foreign key restraint. Why am I getting this?

create database if not exists jokes; use jokes;

create table if not exists user( id int not null auto_increment, userID varchar(20) not null, password varchar(20) not null, Fname varchar (20) not null, Lname varchar (20) not null, email varchar (20) not null, gender varchar (20) not null, age int not null, banned int not null, PRIMARY KEY (id) );

create table if not exists joke( id int not null auto_increment, JokeID int not null, Jtitle varchar(20) not null, Jdescription varchar(200) not null, tag varchar (200), TimeStamp DateTime, PRIMARY KEY (id) ); create table if not exists posted( id int not null auto_increment, JokeID int not null, userID varchar(20) not null, TimeStamp DateTime, PRIMARY KEY (id), FOREIGN KEY (JokeID) REFERENCES joke(JokeID), FOREIGN KEY (userID) REFERENCES user(userID) ); create table if not exists comments( id int not null auto_increment, PostedID int not null, comments varchar(200) not null, TimeStamp DateTime, PRIMARY KEY (id), FOREIGN KEY (PostedID) REFERENCES posted(PostedID) ); create table if not exists review( id int not null auto_INCREMENT, PostedID int not null, reviewScore varchar(30) not null, remark varchar(300) not null, TimeStamp DateTime, PRIMARY KEY (id), FOREIGN KEY (PostedID) REFERENCES posted(PostedID) ); create table if not exists fav_Joke( id int not null auto_increment, JokeID int not null, userID varchar(20) not null, PRIMARY KEY (id), FOREIGN KEY (JokeID) REFERENCES joke(JokeID), FOREIGN KEY (userID) REFERENCES user(userID) ); create table if not exists Friends( id int not null auto_increment, userID varchar(20) not null, friendID int not null, PRIMARY KEY (id), FOREIGN KEY (userID) REFERENCES user(userID), FOREIGN KEY (friendID) REFERENCES user(friendID) );

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions