MySQL Forums
Forum List  »  Newbie

Problem setting foreign key
Posted by: Paul P
Date: September 10, 2017 01:02PM

I'm having a difficult time creating a foreign key in the businesses listed below. The trouble is with the last foreign key to the deals table. I learned this by removing the keys and re-adding them one at a time. It fails when I add the last key.

Please let me know what I'm missing.

CREATE TABLE IF NOT EXISTS deals(
deals_id VARCHAR(40) PRIMARY KEY,
businesses_id VARCHAR(40),
price DECIMAL(9, 2),
created_at TIMESTAMP DEFAULT now()
);

CREATE TABLE IF NOT EXISTS businesses (
businesses_id VARCHAR(40) PRIMARY KEY,
business_name VARCHAR(255),
addresses_id VARCHAR(40),
phones_id VARCHAR(40),
emails_id VARCHAR(40),
company_url VARCHAR(255),
naics_codes_id INT,
FOREIGN KEY (addresses_id) REFERENCES addresses(addresses_id),
FOREIGN KEY (phones_id) REFERENCES phones(phones_id),
FOREIGN KEY (emails_id) REFERENCES emails(emails_id),
FOREIGN KEY (naics_codes_id) REFERENCES naics_codes(naics_codes_id),
FOREIGN KEY (businesses_id) REFERENCES deals(businesses_id)
);

Options: ReplyQuote


Subject
Written By
Posted
Problem setting foreign key
September 10, 2017 01:02PM
September 10, 2017 06:57PM
September 11, 2017 11:58AM


Sorry, only registered users may post in this forum.

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.