2015-09-06 30 views
1

我只是找不到什么不对的代码...mysql的创建表自动递增的ID给错误

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 

我使用节点和mysql NPM模块。请帮忙。

回答

1

你忘ownerid intPRIMARY 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)); 
+0

赞美主,它的作品!出于某种原因,我认为这个错误是'postid'这个词的第一次出现。我真笨... – Mattias