I have a zipcode
table and a shelter
table in my database. I would like the ShelterCity
, ShelterState
and ShelterZip
columns in the shelter table to reference the City
, State
, and ZipCode
columns in the zipcode
table. I have the ZipCode
column (the PK in the zipcode table) as a foreign key in the shelter table
, but cannot seem to figure out how (or if it's even possible) to add the other zipcode
columns so that they update when I type a zipcode into the shelter table.
When I tried to add the ShelterCity
, ShelterState
and ShelterZip
as foreign keys that reference the City
, State
, and ZipCode
columns, I get an error message that looks like this: Error Code 1215. Cannot add foreign key constraint.
The code that I used to attempt to add these foreign keys is as follows:
ALTER TABLE shelter ADD FOREIGN KEY (ShelterCity) REFERENCES zipcode(City);
What am I doing wrong? Thank you in advance!