玩!框架数据库脚本应用程序错误

Play! Framework Database script application error

我正在尝试创建一个数据库来处理我在 Play 中的任务!框架。

这是我的:

build.sbt中:

libraryDependencies ++= Seq(
  jdbc,
  cache,
  ws,
  evolutions,
  "com.typesafe.play" %% "anorm" % "2.5.0",
  "org.scalatestplus.play" %% "scalatestplus-play" % "1.5.0-RC1" % Test
)

conf/evolutions/default/1.sql中:

default.driver = org.h2.Driver
default.url = "jdbc:h2:mem:play"

我正在 app/models/Task.scala 中导入异常并将任务定义为:

import anorm._
import anorm.SqlParser._

case class Task(id: Int, name: String, description: String, group: String)

这是我的 conf/evolutions/default/1.sql:

#Tasks Schema

# ---- !Ups
CREATE SEQUENCE task_id_seq;
CREATE TABLE task (
    id integer NOT NULL DEFAULT nextval('task_id_seq'),
    label varchar(255),
    description varchar(255),
    group varchar(255)
);

# ---- !Downs
DROP TABLE task;
DROP SEQUENCE task_id_seq;

我觉得我做的一切都是正确的,当我在 http://localhost:9000 刷新我的服务器时,这些是我收到的错误:

http://i.imgur.com/MIl8Tds.png

有人告诉我这很好,但是当我单击 "Apply this script" 时,我收到此错误:

http://i.imgur.com/0NY8UGv.png

我该如何解决这个问题?我做错了什么?

以下是有关错误的更多详细信息:

[error] p.a.d.e.DefaultEvolutionsApi - Table "TASK" not found; SQL statement:
DROP TABLE task [42102-191] [ERROR:42102, SQLSTATE:42S02]
[error] application - 

! @6pm2o74ag - Internal server error, for (GET) [/@evolutions/apply/default?redirect=http%3A%2F%2Flocalhost%3A9000%2F] ->

play.api.db.evolutions.InconsistentDatabase: Database 'default' is in an inconsistent state![An evolution has not been applied properly. Please check the problem and resolve it manually before marking it as resolved.]
    at play.api.db.evolutions.DatabaseEvolutions.checkEvolutionsState(EvolutionsApi.scala:276)
    at play.api.db.evolutions.DatabaseEvolutions.databaseEvolutions(EvolutionsApi.scala:126)
    at play.api.db.evolutions.DatabaseEvolutions.scripts(EvolutionsApi.scala:102)
    at play.api.db.evolutions.DatabaseEvolutions.scripts(EvolutionsApi.scala:117)
    at play.api.db.evolutions.DefaultEvolutionsApi.scripts(EvolutionsApi.scala:82)
    at play.api.db.evolutions.EvolutionsWebCommands.handleWebCommand(ApplicationEvolutions.scala:360)
    at play.core.DefaultWebCommands$$anonfun$handleWebCommand.apply(WebCommands.scala:40)
    at play.core.DefaultWebCommands$$anonfun$handleWebCommand.apply(WebCommands.scala:40)
    at scala.collection.immutable.Stream.flatMap(Stream.scala:489)
    at play.core.DefaultWebCommands.handleWebCommand(WebCommands.scala:40)

编辑:

好的,所以我添加了行

  db.default.enabled = true
  applyEvolutions.db=true
  applyEvolutions.default=true
  applyDownEvolutions.default=true

在我的 /application.conf/ 文件中查看是否会有所不同,现在当我尝试 Apply this Script! 时,我收到了一个不同的错误。现在我收到一条错误消息,指出我的脚本中的语法不正确。有人能找到吗?

group是保留关键字,要用的话必须加引号:

CREATE TABLE task (
    id integer NOT NULL DEFAULT nextval('task_id_seq'),
    label varchar(255),
    description varchar(255),
    "group" varchar(255)
)

当您遇到 "inconsistent state" 错误时,您也可以直接转到数据库并检查 play_evolutions table,这有助于了解发生了哪些错误。

此外,我建议您在 运行游戏前先在数据库中测试您的进化。先是 运行 起起伏伏。这样更容易检测语法错误。