play-slick : not found table

1.2k views Asked by At

I want to use play-slick 1.0.0 with play 2.4.0. According to the sample (https://github.com/playframework/play-slick/tree/master/samples/basic), I defined the UserTable like this:

package tables

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)
  }
}

And I implemented the controller as follow:

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)))
  }
}

But, I ran the application and invoked this controller, I got the error

[SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: users)]

How can I create the "users" table?

1

There are 1 answers

1
Biswanath On

You need to either use an existing users table or create a table through slick.

Please see http://slick.typesafe.com/doc/3.0.0/gettingstarted.html#populating-the-database

You need to run db.run(Users.schema.create) in your application.