我只是找不到这段代码有什么问题...
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 模块。请帮忙。
最佳答案
您忘记了 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));
关于mysql创建表id自增报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32423056/