【问题标题】:Play Framework SQL evolution script - error with integer column?播放框架 SQL 进化脚本 - 整数列错误?
【发布时间】:2014-01-15 13:08:51
【问题描述】:

我收到以下错误:

我们收到以下错误:您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册 在 'integer not null, 约束 pk_checkpoint 附近使用正确的语法 主键 (id))' 在第 9 行 [ERROR: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;
}

怎么了?

【问题讨论】:

  • index 是保留字,稍微改一下试试。
  • 谢谢,这解决了我的问题。

标签: mysql sql playframework ebean playframework-2.2


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 2015-09-19
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    相关资源
    最近更新 更多