Mattias
Mattias

Reputation: 725

Mysql create table with auto incrementing id giving error

I just can't find what's wrong with this code...

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) )');

I get the error

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

I use node and mysql npm module. Please help.

Upvotes: 1

Views: 824

Answers (1)

Rahul
Rahul

Reputation: 77906

You forgot a , between ownerid int and PRIMARY KEY (postid) as pointed below

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

Your CREATE TABLE statement should be

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));

Upvotes: 1

Related Questions