2015-09-06 51 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