由於JoshSGoman comment指出有關answer of Mike-s,則不會創建表。我設法使它工作通過稍微修改了第一個答案代碼:
val coffees = TableQuery[Coffees]
try {
def createTableIfNotInTables(tables: Vector[MTable]): Future[Unit] = {
if (!tables.exists(_.name.name == events.baseTableRow.tableName)) {
db.run(coffees.schema.create)
} else {
Future()
}
}
val createTableIfNotExist: Future[Unit] = db.run(MTable.getTables).flatMap(createTableIfNotInTables)
Await.result(createTableIfNotExist, Duration.Inf)
} finally db.close
用下面的進口:
import slick.jdbc.meta.MTable
import slick.driver.SQLiteDriver.api._
import scala.concurrent.{Await, Future}
import scala.concurrent.duration.Duration
import scala.concurrent.ExecutionContext.Implicits.global
我不斷收到一個執行上下文錯誤,如果我導入'scala.concurrent.ExecutionContext.Implicits.global'但是沒有創建表,錯誤消失。我該如何解決這個問題? – JoshSGman