MySQL Forums
Forum List  »  Newbie

ERROR 3780: Referencing column 'PO' and referenced column 'Order Number' in foreign key constraint
Posted by: Paul Kagan
Date: February 01, 2021 10:35AM

I get the following error when trying to add a foreign key...

I don't know why it does not work...


First I post the details of the error then I will post the structure of the tables.



ERROR 3780: Referencing column 'PO' and referenced column 'Order Number' in foreign key constraint

Operation failed: There was an error while applying the SQL script to the database.
Executing:
ALTER TABLE `awldm`.`services`
ADD CONSTRAINT `Purchase_Order`
FOREIGN KEY (`PO`)
REFERENCES `awldm`.`purchase orders` (`Order Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ERROR 3780: Referencing column 'PO' and referenced column 'Order Number' in foreign key constraint 'Purchase_Order' are incompatible.
SQL Statement:
ALTER TABLE `awldm`.`services`
ADD CONSTRAINT `Purchase_Order`
FOREIGN KEY (`PO`)
REFERENCES `awldm`.`purchase orders` (`Order Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION


Tables are as follows:

CREATE TABLE `services` (
`Service` int NOT NULL,
`PO` varchar(35) NOT NULL,
PRIMARY KEY (`Service`,`PO`),
UNIQUE KEY `PO_UNIQUE` (`PO`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;


CREATE TABLE `purchase orders` (
`Order Number` varchar(35) CHARACTER SET latin1 NOT NULL,
`Supplier` varchar(77) CHARACTER SET latin1 NOT NULL,
`Date` date NOT NULL,
PRIMARY KEY (`Order Number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Options: ReplyQuote


Subject
Written By
Posted
ERROR 3780: Referencing column 'PO' and referenced column 'Order Number' in foreign key constraint
February 01, 2021 10:35AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.