MySql 表,错误 #1064 和错误 #1068 定义了多个主键

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16696899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:42:47  来源:igfitidea点击:

MySql tables, error #1064 & error #1068 Multiple primary key defined

mysqlsqlcreate-table

提问by MEDZ

I have got errors when I tried to install the MySql tables, error:

当我尝试安装 MySql 表时出现错误,错误:

"#1064 - You have an error in your SQL syntax"

“#1064 - 你的 SQL 语法有错误”

and error:

和错误:

"#1068 - Multiple primary key defined "

“#1068 - 定义了多个主键”

This is the database:

这是数据库:

CREATE TABLE messages (
msg_id INT PRIMARY KEY AUTO_INCREMENT,
message VARCHAR(200),
uid_fk INT(10),
ip VARCHAR(45),
created INT(10),
uploads VARCHAR(50),
profile_uid INT(10)

PRIMARY KEY (`msg_id`),
KEY `uid_fk` (`uid_fk`)

);


CREATE TABLE comments (
com_id INT PRIMARY KEY AUTO_INCREMENT,
comment VARCHAR(200),
msg_id_fk INT(10),
uid_fk INT(10),
ip VARCHAR(45),
created INT(10),

PRIMARY KEY (`com_id`),
KEY `msg_id_fk` (`msg_id_fk`),
KEY `uid_fk` (`uid_fk`)

);


CREATE TABLE likes (
like_id INT PRIMARY KEY AUTO_INCREMENT,
msg_id_fk INT(10),
uid_fk INT(10),

PRIMARY KEY (`like_id`),
KEY `msg_id_fk` (`msg_id_fk`),
KEY `uid_fk` (`uid_fk`)

);


CREATE TABLE user_uploads (
id INT PRIMARY KEY AUTO_INCREMENT,
image_path VARCHAR(500),
uid_fk INT(10),

PRIMARY KEY (`id`),
KEY `uid_fk` (`uid_fk`)

);


CREATE TABLE follow_user (
fid INT PRIMARY KEY AUTO_INCREMENT,
uid_fk INT(10),
following_uid INT(10),

PRIMARY KEY (`fid`),
KEY `uid_fk` (`uid_fk`)

);

these are the errors images:

这些是错误图像:

How to fix it?

如何解决?

回答by Ven

Either use the inline syntax (msg_id INT PRIMARY KEY AUTO_INCREMENT) or declare it afterwards (PRIMARY KEY (com_id)), not both : they conflict.

要么使用内联语法 ( msg_id INT PRIMARY KEY AUTO_INCREMENT) 要么在之后声明它 ( PRIMARY KEY (com_id )),而不是两者:它们会发生冲突。

回答by Michael

And the syntax error in the messages table is simply a missing comma at the end of the profile_uid INT(10)line.

消息表中的语法错误只是profile_uid INT(10)行尾缺少逗号。