H2内存数据库,[JdbcSQLException: Table "USERINFO" not found; SQL声明:

H2 in-memory database,[JdbcSQLException: Table "USERINFO" not found; SQL statement:

我在内存数据库中使用 H2 和播放框架我是初学者所以我决定制作一个小的登录注册应用程序来开始使用 scala 并播放我决定在内存数据库中使用 H2 但它抛出 Table not foundexception 我在 sql 文件中编写了一个脚本,当我启动应用程序时播放要求我应用此脚本但是当我尝试向其中插入数据时它抛出异常,异常是

 [JdbcSQLException: Table "USERINFO" not found; SQL statement:
insert into USERINFO (fname,lname,email,userName,pwd,age,choice,gender) values (?,?,?,?,?,?,?,?) [42102-175]]

这里是 sql 文件的脚本

# --- !Ups
CREATE TABLE USERINFO(
    fname varchar(255) NOT NULL,
    lname varchar(255) NOT NULL,
    email varchar(255) NOT NULL,
    userName varchar(255) NOT NULL,
    pwd varchar(255) NOT NULL,
    age Int NOT NULL,
    choice varchar(255) NOT NULL,
    gender varchar(255) NOT NULL
);

DROP TABLE USERINFO;

这里是 application.conf

的一部分
 db.default.driver=org.h2.Driver
 db.default.url="jdbc:h2:mem:play"
 db.default.user=sa
 db.default.password=""
 db_close_delay=-1

这里是application.scala

的代码
package controllers

import play.api._
import play.api.mvc._
import play.api.data._
import play.api.data.Forms._
import views.html.defaultpages.badRequest
import play.api.data.validation.Constraints._

import models.User



object Application extends Controller {


  val RegisterForm = Form(
mapping(

"fname" -> nonEmptyText(1, 20),
"lname" -> nonEmptyText(1, 20),
"email" -> email,
"userName" -> nonEmptyText(1, 20),
"password" -> nonEmptyText(1, 20),
"age" -> number,
"choice" -> text,
"gender" -> text

)
(User.apply)(User.unapply)
verifying("Ag should be greater then or eual to  18",model=> model.age match 
    {
  case (age) => age>=18

    })
)
  def index = Action {
    Ok(views.html.index(RegisterForm))
  }

 def register =Action {implicit request => 

  RegisterForm.bindFromRequest().fold(
      hasErrors => BadRequest(views.html.index(hasErrors))
        , 
      success => {  

     val result = User.save(success)
println(s"INSERT succeeded, id = $result")
Redirect(routes.Application.index)
      }
)
}

}

这里是 User.scala

的代码
package models
import anorm._
import play.api.db.DB
import anorm.SqlParser._
import play.api.Play.current

case class User (

  fname:String,
  lname:String,
  email:String,
  userName:String,
  password:String,
  age:Int,
  choice:String,
  gender:String

)
object User{

  val userinfo = {
    get[String]("fname") ~ 
    get[String]("lname") ~ 
    get[String]("email") ~ 
    get[String]("userName") ~ 
    get[String]("pwd") ~ 
    get[Int]("age") ~ 
    get[String]("choice") ~ 
    get[String]("gender") map {
    case fname ~ lname ~email~ userName ~ password ~age~ choice~gender => 
      User(fname , lname ,email, userName , password ,age, choice,gender)
  }
}
  def save(ud:User):Option[Long]= {
     val id :Option[Long] = DB.withConnection {implicit c => 
    SQL ("insert into USERINFO (fname,lname,email,userName,pwd,age,choice,gender) values ({fname},{lname},{email},{userName},{password},{age},{choice},{gender})")
    .on('fname -> ud.fname, 'lname ->ud.lname ,'email ->ud.email, 'userName->ud.userName , 'password->ud.password ,'age->ud.age, 'choice->ud.choice,'gender->ud.gender)
    .executeInsert()  
    }
    id 
  }

 /* def save(ud:User)= {
     DB.withConnection {implicit c => 
    SQL ("insert into USERINFO (fname,lname,email,userName,pwd,age,choice,gender) values ({fname},{lname},{email},{userName},{password},{age},{choice},{gender})")
    .on('fname -> ud.fname, 'lname ->ud.lname ,'email ->ud.email, 'userName->ud.userName , 'password->ud.password ,'age->ud.age, 'choice->ud.choice,'gender->ud.gender)
    .executeUpdate()  
    }

  }
 */ 
  }

我尝试了 executeUpdateexecuteInsert 但没有任何改变请帮助我哪里做错了

1.

最有可能的问题是 Play!框架在查询中引用了标识符名称(table名称,列名称),因此您需要在'create table'语句中也引用table名称:

    CREATE TABLE "USERINFO"(
    "fname" varchar(255) NOT NULL,
    "lname" varchar(255) NOT NULL,
    "email" varchar(255) NOT NULL,
    "userName" varchar(255) NOT NULL,
    "pwd" varchar(255) NOT NULL,
    "age" Int NOT NULL,
    "choice" varchar(255) NOT NULL,
    "gender" varchar(255) NOT NULL
);

2.

如果没有任何帮助。还有一种方法。我阅读了迁移文档,必须将 libraryDependencies += evolutions 应用到 build.sbt。

这些不是必需的,它们会自动应用进化(不显示数据库 'default' 需要进化!):

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