Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在我的项目中,我有一个x_user_module_perm表,我需要为它保留一个主键和一个复合主键_Mysql_Sql - Fatal编程技术网

Mysql 在我的项目中,我有一个x_user_module_perm表,我需要为它保留一个主键和一个复合主键

Mysql 在我的项目中,我有一个x_user_module_perm表,我需要为它保留一个主键和一个复合主键,mysql,sql,Mysql,Sql,我使用的语法是:- CREATE TABLE `x_user_module_perm` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `user_id` bigint(20) NULL DEFAULT NULL, `module_id` bigint(20) NULL DEFAULT NULL, `create_time` datetime NULL DEFAULT NULL, `update_time` datetime NULL DEFAULT NUL

我使用的语法是:-

CREATE TABLE `x_user_module_perm` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NULL DEFAULT NULL,
`module_id` bigint(20) NULL DEFAULT NULL,
`create_time` datetime NULL DEFAULT NULL,
`update_time` datetime NULL DEFAULT NULL,
`added_by_id` bigint(20) NULL DEFAULT NULL,
`upd_by_id` bigint(20) NULL DEFAULT NULL,
`is_allowed` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
PRIMARY KEY (`user_id`,`module_id`),
KEY `x_user_module_perm_idx_module_id` (`module_id`),
KEY `x_user_module_perm_idx_user_id` (`user_id`),
CONSTRAINT `x_user_module_perm_FK_module_id` FOREIGN KEY (`module_id`) REFERENCES `x_modules_master` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `x_user_module_perm_FK_user_id` FOREIGN KEY (`user_id`) REFERENCES `x_portal_user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ;
我遇到一个错误,无法使用两个主键


有可能吗,盖伊的请引导我

尝试将
主键(用户id,模块id)
更改为
唯一索引(用户id,模块id)

正如错误所述,您不能有两个主键为什么不将id用作复合键的一部分
主键(id,用户id,模块id),
没有Abhik chakraborty我可能想过这样做,但我们可以有entrie(1,2,5)(2,2,5)(3,2,5)@草莓,对不起,我把代码改回去了,但两者都可以使用:)