播放框架 SQL 演变脚本 - 整数列错误



我收到以下错误:

我们收到以下错误:您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本对应的手册以了解 在"整数不为空,约束pk_checkpoint"附近使用的正确语法 主键 (id))' 在第 9 行 [错误:1064, SQLSTATE:42000],而 尝试运行此 SQL 脚本:

生成的 SQL:

1 # --- Rev:1,Ups - 491c235
2
3 create table checkpoint (
4 id                        bigint auto_increment not null,
5 name                      varchar(80) not null,
6 longitude                 double not null,
7 latitude                  double not null,
8 points                    integer not null,
9 message                   varchar(160) not null,
10 scenario_id               bigint,
11 index                     integer not null,
12 constraint pk_checkpoint primary key (id))
13;

我的模型:

@Entity
public class Checkpoint extends Model {
    @Id
    public Long id;
    @Column(length = 80, nullable = false)
    public String name;
    @Column(nullable = false)
    public double longitude;
    @Column(nullable = false)
    public double latitude;
    @Column(nullable = false)
    public int points;
    @Column(length = 160, nullable = false)
    public String message;
    @OneToMany(cascade = CascadeType.ALL)
    public List<CheckpointAnswer> possibleAnswers = new ArrayList<CheckpointAnswer>();
    @ManyToOne(cascade = CascadeType.PERSIST)
    public Scenario scenario;
    @Column(nullable = false)
    public int index;
}

怎么了?

为了补充上述内容,并且不减损避免保留字可能是一个好主意的观点,如果您真的希望该列被称为索引,您可以使用MySQL工作台或您选择的sql工具手动创建表,使用列名("索引")周围的反引号。至少在 Scala/anorm 中,这不会改变你在源代码中引用列的方式。(对于跨数据库兼容性,将MySQL配置为使用双引号而不是反引号可能也是一个好主意。此处进一步讨论。

最新更新