“用户表”创建成功。每个列和类型都与“用户表”相同。但是,当我创建一个名为“ user_role”的关联表时,无法调用“ user table”。在将MySQL与MariaDB结合使用时,只会出现此错误。在Windows中安装mysql并使用类似方法就可以了。在不更改该表名的情况下,我可以做些什么来使其正确吗?
转储了两个表,因为我忘记了将原始代码放在哪里。但我会一样。
-d
-> CREATE TABLE `user` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,`email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,`name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,`course_id` bigint(20) DEFAULT NULL,`password` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,PRIMARY KEY (`id`),KEY `FKj8ce5cjkm11igsffixdxexrr9` (`course_id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `users` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,`name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,`email` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,KEY `course_id` (`course_id`),CONSTRAINT `users_ibfk_1` FOREIGN KEY (`course_id`) REFERENCES `course` (`id`) ON DELETE SET NULL) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `role` (
`id` int(11) NOT NULL AUTO_INCREMENT,`role_name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
create table `user_role`(
`id` int auto_increment not null,`user_id_fk` bigint,`role_id_fk` int,primary key (`id`),foreign key (`user_id_fk`) references `user`(`id`),foreign key (`role_id_fk`) references `role`(`id`)
);
无效,但references user(id)
正常。有什么办法可以使其工作?或者只是更改名称?