我找不到这段代码的错误......
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模块。请帮忙。
答案 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));