2014-01-15 39 views
0

我得到了以下錯誤:Play Framework SQL演變腳本 - 整數列錯誤?

We got the following 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 'integer not null, constraint pk_checkpoint primary key (id))' at line 9 [ERROR:1064, SQLSTATE:42000], while trying to run this SQL script:

生成的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; 
} 

有什麼不對?

+1

0123是索引是保留字,請嘗試稍微更改它。 – dwjv

+0

謝謝,這解決了我的問題。 – pmichna

回答

0

爲了增加上述內容,並且不要偏離避免保留字的觀點,如果您真的希望列名爲index,您可以使用MySQL工作臺或SQL手動創建表使用圍繞列名稱(`索引')的反引號選擇工具。至少在Scala/anorm中,這不會改變您在源代碼中引用列的方式。 (對於跨數據庫兼容性,將MySQL配置爲使用雙引號而不是反引號也可能是一個好主意。進一步討論here。)