我正在使用 MySQL 5 尝试创建两个表。下面是两张表:
DROP TABLE IF EXISTS `users` ;
CREATE TABLE IF NOT EXISTS `users` (
`username` VARCHAR(50) not null ,
`password` VARCHAR(50) not null,
`enabled` boolean not null,
`accountNonExpired` boolean not null,
`accountNonLocked` boolean not null,
`credentialsNonExpired` boolean not null,
PRIMARY KEY (`username`)
) ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
DROP TABLE IF EXISTS `authorities` ;
create table IF NOT EXISTS `authorities` (
`username` VARCHAR(50) not null ,
`authority` varchar(50) not null,
foreign key (`username`) references `users` (`username`),
unique index authorities_idx_1 (username, authority)
) engine = InnoDb;
当我尝试执行此语句时,会创建 users 表,但随后出现错误:
Error Code: 1005
Can't create table 'dental.authorities' (errno: 150)
当两个引用的列相同时,我不明白为什么这个外键会失败。在那儿