Este es mi codigo:
CREATE TABLE users(
user_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
user_name VARCHAR(45) NOT NULL,
user_phone VARCHAR(16) NOT NULL,
user_email VARCHAR(50) NOT NULL UNIQUE,
user_pass VARCHAR(45) NOT NULL
);
CREATE TABLE posts(
post_id INT NOT NULL,
post_date DATE NOT NULL,
post_province_origin VARCHAR(50) NOT NULL,
post_province_goal VARCHAR(50) NOT NULL,
post_locality_origin VARCHAR(50) NOT NULL,
post_locality_goal VARCHAR(50) NOT NULL,
post_descrip VARCHAR(200) NOT NULL,
user_id INT,
post_user_name VARCHAR(25) NOT NULL,
post_user_phone VARCHAR(13) NOT NULL,
PRIMARY KEY(user_id, post_id),
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
CREATE TABLE messages(
msg_id INT NOT NULL,
msg_price VARCHAR(50) NOT NULL,
post_id INT,
PRIMARY KEY (msg_id, post_id),
FOREIGN KEY (post_id) REFERENCES posts(post_id)
);
el error que tengo es en la tabla de messages...
No puedo crear tabla app_web_dl
.messages
(Error: 150 "Foreign key constraint is incorrectly formed")
que puede estar mal? vi que muchos ponen el constraint.. pero en la universidad no me lo enseñaron .. no se como se usa el contraint...