Mysql创建表,自动递增id给出错误

时间:2015-09-06 11:29:23

标签: mysql sql node.js

我找不到这段代码的错误......

connection.query('CREATE TABLE posts (postid int NOT NULL AUTO_INCREMENT, posttitle varchar(255) NOT NULL, postdate datetime NOT NULL, deleted boolean, ownerid int PRIMARY KEY (postid) )');

我收到错误

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(postid) )' at line 1

我使用node和mysql npm模块。请帮忙。

1 个答案:

答案 0 :(得分:1)

您忘记了,ownerid int之间的PRIMARY KEY (postid),如下所示

ownerid int PRIMARY KEY (postid)
           ^...Here  

您的CREATE TABLE声明应为

CREATE TABLE posts (postid int NOT NULL AUTO_INCREMENT, 
posttitle varchar(255) NOT NULL, 
postdate datetime NOT NULL, 
deleted boolean, 
ownerid int, //Add comma here
 PRIMARY KEY (postid));