I'm going over a coding assignment, and I'm running into an error I can't solve.
I build a database and try to insert tables into it:
CREATE TABLE city(
city_id INT NOT NULL,
city_name VARCHAR(50) NOT NULL,
state VARCHAR(20),
zip CHAR(10) NOT NULL,
country VARCHAR(60) NOT NULL,
PRIMARY KEY (city_id)
);
CREATE TABLE users(
user_id INT NOT NULL,
first_name VARCHAR(25) NOT NULL,
last_name VARCHAR(25) NOT NULL,
city VARCHAR(50),
state VARCHAR(20),
zip_code CHAR(10),
country VARCHAR(60),
phone VARCHAR(12),
email VARCHAR(30) NOT NULL,
user_password VARCHAR(25) NOT NULL,
PRIMARY KEY (user_id),
FOREIGN KEY(city) REFERENCES city(city_name),
FOREIGN KEY(state) REFERENCES city(state),
FOREIGN KEY(zip_code) REFERENCES city(zip),
FOREIGN KEY(country) REFERENCES city(country)
);
Afterwards I get this error: error 1822 failed to add a foreign key constraint. Missing index for constraint 'users_ibfk_1' in the referenced table 'city'
I tried tweaking my nulls to align, and it still failed. I attempted renaming