Ciao, CON MYSQL
Codice PHP:
CREATE TABLE users (
    
user_id INT NOT NULL PRIMARY KEY,
    
first_name CHAR(32),
    
last_name CHAR(32),
    
zip_code INT,
    
phone INT
    
)ENGINE=INNODB;

CREATE TABLE zip (
    
zip_code INT,
    
city_id INT,
    
PRIMARY KEY(zip_code)
    )
ENGINE=INNODB
poi ho fatto
Codice PHP:
ALTER TABLE users ADD FOREIGN KEY (zip_codeREFERENCES zip(zip_codeON DELETE CASCADE ON UPDATE CASCADE
e cercando di inserire i dati mi da errore
Codice PHP:
INSERT INTO users VALUES(1Franco', 'Rossi', 11100, 123456);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`example`.`users`, CONSTRAINT `users_ibfk_1` FOREIGN KEY (`zip_code`) REFERENCES `zip` (`zip_code`) ON DELETE CASCADE ON UPDATE CASCADE) 
Quale è il problema?