MySQL 5 を使用して 2 つのテーブルを作成しようとしています。以下に 2 つのテーブルを示します。
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)
参照される 2 つの列が同一である場合に、この外部キーが失敗する理由がわかりません。ある