Question: However, it is generating an error Cannot add foreign key constraint. Can you please tell me what is wrong with both of the below codes?
However, it is generating an error "Cannot add foreign key constraint". Can you please tell me what is wrong with both of the below codes?
SQL Fiddle MySQL 5.6 Build Schema 1 Create Table employee ( 2 employee_id INTEGER NOT NULL, 3 first name varchar (30) NOT NULL, 4 last_name varchar (30) NOT NULL, 5 hire_date date NOT NULL, 6 job_title varchar (30) NOT NULL, 7 shop_id INTEGER NOT NULL, 8 PRIMARY KEY (employee_id), 9 FOREIGN KEY (shop_id) REFERENCES coffee shop (shop_id ) 10 ); Edit Fullscreen View Sample Fiddle * Cannot add foreign key constraint Browser E CClea SQL Fiddle [:] 1 Create Table coffee ( 2 3 4 MySQL 5.6 ) coffee_id INTEGER NOT NULL, Build Schema shop_id INTEGER NOT NULL, supplier_id INTEGER NOT NULL, 5 coffee_name varchar (30) NOT NULL, 6 prce_per_pound NUMERIC (5,2) NOT NULL, 7 PRIMARY KEY (coffee_id), 8 FOREIGN KEY (shop_id) REFERENCES coffee_shop(shop_id), FOREIGN KEY (supplier_id) REFERENCES supplier (supplier_id) 9 10 View Sample Fiddle Edit Fullscreen Browser * Cannot add foreign key constraint CClear [i]+
Step by Step Solution
3.45 Rating (152 Votes )
There are 3 Steps involved in it
1 The error Cannot add foreign key constraint is occurring because the table coffee shop has not bee... View full answer
Get step-by-step solutions from verified subject matter experts
