NutzCN Logo
问答 默认的建表语句出错1064
发布于 1347天前 作者 junk123321 940 次浏览 复制 上一个帖子 下一个帖子
标签:

一个pojo Position,使用Daos.createTablesInPackage(dao, "com.xx.pojo", false) 自动建表,有些表可以自动建好,

import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.Table;

@Table
public class Position {

    @Id
    private int id;

    @Name
    private String name;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

出错信息

Caused by: org.nutz.dao.DaoException: !Nutz SQL Error: 'CREATE TABLE position(
id INT(32) AUTO_INCREMENT,
name VARCHAR(128) UNIQUE NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB CHARSET=utf8'
PreparedStatement: 
'CREATE TABLE position(
id INT(32) AUTO_INCREMENT,
name VARCHAR(128) UNIQUE NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB CHARSET=utf8'
CaseMessage=You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'position(
id INT(32) AUTO_INCREMENT,
name VARCHAR(128) UNIQUE NOT NULL,
PRIMARY ' at line 1

这个语句很简单,在phpmyadmin里面运行该语句,同样报错,但,把“CREATE TABLE position(” 改成“CREATE TABLE position (”,就可以运行了,只是在position后面加了个空格,请问如何修改,才能继续自动建表?谢谢!

3 回复

非常奇怪的问题,“CREATE TABLE position1(”也没问题,偏偏就是“CREATE TABLE position(”有问题

那是关键字

你是对的
position在mysql里面不是关键字
参考:https://dev.mysql.com/doc/refman/5.7/en/keywords.html
在maria db里面是关键字。。。
参考:https://mariadb.com/kb/en/reserved-words/

添加回复
请先登陆
回到顶部