我想在播放2.4.0时使用play-slick 1.0.0。 根据示例(https://github.com/playframework/play-slick/tree/master/samples/basic),我像这样定义了UserTable:
包裹表
import models.User
import scala.slick.driver.JdbcProfile
trait UserTable {
protected val driver: JdbcProfile
import driver.api._
class Users(tag: Tag) extends Table[User](tag, "users"){
def ID = column[Long]("id", O.PrimaryKey, O.AutoInc)
def email = column[String]("email", O.NotNull)
def password = column[String]("password", O.NotNull)
def * = (ID, email, password) <> (User.tupled, User.unapply)
}
}
我按照以下方式实施了控制器:
package controllers
import play.api._
import play.api.mvc._
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfig
import tables.UserTable
import scala.slick.driver.JdbcProfile
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import models.User
import tables.UserTable
class UserController extends Controller with UserTable with HasDatabaseConfig[JdbcProfile]{
val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
import driver.api._
val Users = TableQuery[Users]
def index = Action.async {
db.run(Users.result).map(res => Ok(views.html.User.index(res.toList)))
}
}
但是,我运行了应用程序并调用了这个控制器,我收到了错误
[SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: users)]
如何创建“用户”表?
答案 0 :(得分:1)
您需要使用现有用户表或通过光滑创建表。
请参阅http://slick.typesafe.com/doc/3.0.0/gettingstarted.html#populating-the-database
您需要在应用程序中运行db.run(Users.schema.create)。