Skip to content
Advertisement

Tag: foreign-keys

Alter Table Foreign Key

I’m trying to add barista_grade_id to the baristas table as a foreign key and I’ve looked every where on what syntax to use and it seems to be unanimous that this is the correct way. I did it before this and it worked. but because of some mistakes I deleted it and redo it again, but for whatever reason it

Insert with Foreign Key Contraints

In the above code, I want to add the distinct values from column make from vehicles into column makeID in makeModel but I get the error INSERT INTO makeModel (makeID) SELECT DISTINCT (make) FROM vehicle Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (`dealership`.`makemodel`, CONSTRAINT `makemodel_ibfk_2` FOREIGN KEY (`modelID`) REFERENCES `model` (`ID`)) Answer

SQL FOREIGN KEY ERROR (errno: 150 “Foreign key constraint is incorrectly formed”)

Hi I have this three very simple tables but I can’t fix it to get the right format of foreign key. CREATE TABLE company( company_name varchar(30) UNIQUE NOT NULL, bid INT(15) NOT NULL UNIQUE, cid INT(15) NOT NULL UNIQUE, FOREIGN KEY (bid) REFERENCES branch(branch_id), FOREIGN KEY (cid) REFERENCES contact(contact_id) ); CREATE TABLE branch( branch_id INT(15) NOT NULL AUTO_INCREMENT UNIQUE, branch_type

MYSQL table wont allow multiple foreign keys

I know this has been asked again and again, and I’ve tried so many times and don’t understand why I keep getting errors, but I’m trying to connect the order details table to the order items, users and payment table, but SQL is coming up with. (this is for a school project) I’ve been able to connect a table with

mysql error 1822 when trying to create new table with a FOREIGN KEY

trying the following code: Give back Error Code: 1822. Failed to add the foreign key constraint. Missing index for constraint ‘stock_ibfk_1’ in the referenced table ‘donation’. Why? how can I solve this problem? Answer to create a foreign key relationship, the parent table column on which you are creating relation must be unique or primary and they must have the

Advertisement