Хотел связать две таблицы ROLE и USERS.
Данные таблиц:
Table: role
Columns:
id_role int(11) AI PK
role varchar(45)
Table: users
Columns:
id_user int(11) AI PK
username varchar(45)
password varchar(45)
role int(11) PK
department int(11) PK
При запросе выскакивает ошибка:
Operation failed: There was an error while applying the SQL script to the database.
ERROR 1215: Cannot add foreign key constraintExecuting:
ALTER TABLE `moysclad`.`role`
ADD CONSTRAINT `id`
FOREIGN KEY (`id_role`)
REFERENCES `moysclad`.`users` (`role`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
Operation failed: There was an error while applying the SQL script to the database.
ERROR 1215: Cannot add foreign key constraint
SQL Statement:
ALTER TABLE `moysclad`.`role`
ADD CONSTRAINT `id`
FOREIGN KEY (`id_role`)
REFERENCES `moysclad`.`users` (`role`)
ON DELETE NO ACTION
ON UPDATE NO ACTION
Что я делаю не так?