我使用Play Framework 2.5和Slick 3.1 git here下载了一个入门应用程序。
当我添加一个简单的名为" test"到Project.scala。我收到这个错误:
[JdbcSQLException: Column "TEST" not found; SQL statement:
select "ID", "NAME", "TEST" from "PROJECT" [42122-187]]
我只是通过添加参数test和 ProjectsTable 类来更改 Project 案例类,其中包含函数test,*和?:
case class Project(id: Long, name: String, test: String)
private class ProjectsTable(tag: Tag) extends Table[Project](tag, "PROJECT") {
def id = column[Long]("ID", O.AutoInc, O.PrimaryKey)
def name = column[String]("NAME")
def test = column[String]("TEST")
def * = (id, name, test) <> (Project.tupled, Project.unapply)
def ? = (id.?, name.?, test.?).shaped.<>({ r => import r._; _1.map(_ => Project.tupled((_1.get, _2.get, _3.get))) }, (_: Any) => throw new Exception("Inserting into ? projection not supported."))
}
功能:创建
def create(name: String): Future[Long] = {
val project = Project(0, name, "d")
db.run(Projects returning Projects.map(_.id) += project)
}
非常感谢你的帮助!
答案 0 :(得分:0)
通过向test
模型添加字段ProjectsTable
,您告诉Slick数据库表PROJECT
有一个名为test
的列 - 但表PROJECT
}没有名为test
的列。
您可以在此处查看SQL架构:https://github.com/nemoo/play-slick3-example/blob/6c122970d7506bedb9230e3a31c30a5c7e27e93b/conf/evolutions/default/1.sql