I'm trying to create roles management system and I get error while trying to create mysql table with foreign keys. I checked w3school documents and everything seems to be same.
My error:
#1215 - Cannot add foreign key constraint
MySQL:
CREATE TABLE user_role (
user_id INTEGER UNSIGNED NOT NULL,
role_id INTEGER UNSIGNED NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(user_id),
FOREIGN KEY (role_id) REFERENCES roles(role_id)
);
I run this command:
SHOW ENGINE INNODB STATUS;
And got this:
Cannot find an index in the referenced table where the referenced columns appear as the first columns, or column types in the table and the referenced table do not match for constraint. Note that the internal storage type of ENUM and SET changed in tables created with >= InnoDB-4.1.12, and such columns in old tables cannot be referenced by such columns in new tables.