【问题标题】:Mysql create table with auto incrementing id giving errorMysql创建具有自动递增ID的表给出错误
【发布时间】:2015-09-06 11:29:23
【问题描述】:

我只是找不到这段代码有什么问题......

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 模块。请帮忙。

【问题讨论】:

    标签: mysql sql node.js


    【解决方案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));
    

    【讨论】:

    • 赞美主,成功了!出于某种原因,我认为该错误是“postid”一词的第一次出现。我很笨……
    猜你喜欢
    • 2016-05-28
    • 2011-02-18
    • 1970-01-01
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 2011-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多