I have Two tables: sys_users
and sys_roles
.
After creating two tables I tried to create foreign keys with the following statement:
Alter table `hr_001`.`sys_users`
add constraint
`constraint_user_role` foreign key (`Role`) references
`hr_001`.`sys_roles`(`ID`) on delete Set null
But it gives me the following error
Query: Alter table
hr_001
.sys_users
add constraintconstraint_user_role
foreign key (Role
) referenceshr_001
.sys_roles
(ID
...Error Code: 1005 Can't create table 'hr_001.#sql-2e5c_1f' (errno: 150)
My table creation statements are
CREATE TABLE `sys_users` (
`ID` INT (10) UNSIGNED NOT NULL AUTO_INCREMENT,
`Username` VARCHAR (100) NOT NULL,
`Password` VARCHAR (100) NOT NULL,
`Active` TINYINT (1) NOT NULL DEFAULT '1',
`Role` INT (11) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE = INNODB AUTO_INCREMENT = 2 DEFAULT CHARSET = utf8;
CREATE TABLE `sys_roles` (
`ID` INT (10) UNSIGNED NOT NULL AUTO_INCREMENT,
`Role` VARCHAR (50) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE = INNODB AUTO_INCREMENT = 2 DEFAULT CHARSET = utf8;
Can anyone help on this?