我试图创建一个简单的控制器/模型(基于play 2.0的示例代码) 并得到了关于DB演变的信息:
Database 'default' needs evolution!
An SQL script will be run on your database - "Apply this script now"
1 # --- Rev:1,Ups - fbdc2fd
2 create table group (
3 id bigint not null,
4 name varchar(255),
5 description varchar(255),
6 due_date timestamp,
7 constraint pk_group primary key (id))
8 ;
9
10 create sequence group_seq;
但是当点击按钮时,我收到以下错误消息:
Database 'default' is in inconsistent state!
An evolution has not been applied properly. Please check the problem and resolve it manually before making it as resolved
We got the following error: SQLステートメントに文法エラーがあります "CREATE TABLE GROUP[*] ( ID BIGINT NOT NULL, NAME VARCHAR(255), DESCRIPTION VARCHAR(255), DUE_DATE TIMESTAMP, CONSTRAINT PK_GROUP PRIMARY KEY (ID)) "; 期待されるステートメント "identifier" Syntax error in SQL statement "CREATE TABLE GROUP[*] ( ID BIGINT NOT NULL, NAME VARCHAR(255), DESCRIPTION VARCHAR(255), DUE_DATE TIMESTAMP, CONSTRAINT PK_GROUP PRIMARY KEY (ID)) "; expected "identifier"; SQL statement: create table group ( id bigint not null, name varchar(255), description varchar(255), due_date timestamp, constraint pk_group primary key (id)) [42001-158] [ERROR:42001, SQLSTATE:42001], while trying to run this SQL script:
1# --- Rev:1,Ups - fbdc2fd
2
3 create table group (
4 id bigint not null,
5 name varchar(255),
6 description varchar(255),
7 due_date timestamp,
8 constraint pk_group primary key (id))
9 ;
10
11 create sequence group_seq;
我的配置文件
#DB setting
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
# Ebean configuration
ebean.default="models.*"
我的控制器
public class Application extends Controller {
/**
*
* @return
*/
public static Result index() {
Group g = new Group("New group Test","This is a test !");
g.save();
return ok(index.render("Render page"));
}
}
最后我的模特:
@Entity
public class Group extends Model {
public static Finder<Long,Group> find = new Finder (Long.class, Group.class);
@Id
public Long id;
@Required
public String name;
@Required
public String description;
@DateTime(pattern = "MM/dd/yy")
public Date dueDate;
/**
* ToString method
*/
public String toString() {
return "Group(" + id + ") in project " + name;
}
/**
* Constructor
* @param name
* @param description
*/
public Group(String name, String description){
this.name=name;
this.description=description;
}
}
有人遇到同样的问题吗? 谢谢!
答案 0 :(得分:5)
可能是您的表(组)的名称是问题,因为它是一个SQL关键字。尝试引用表名(&#34; group&#34;)或测试如果使用不同的表名会发生什么。
答案 1 :(得分:1)
群组是一个关键字,因此请为您的模型找到其他名称而不是Group
,这样就可以了。
顺便说一下也修好了你的Finder:
public static Finder<Long,MyGroup> find = new Finder<Long,MyGroup> (Long.class, MyGroup.class);
您也可以强制使用其他表格的名称以避免与关键字发生冲突,但我会逐个更改模型名称并使用表格和模型。
@Entity
@Table(name = "group_table")
public class Group extends Model {
...
}