Scala Slick: MTable.getTables return empty vector/list

冷暖自知 提交于 2020-01-21 15:21:39

问题


Slick is returning result in DML queries, throwing exceptions while executing table creation actions, but the MTable.getTables return empty vector/list. I am using MySQL as SQL solution.

  println(Await.result(db.run(MTable.getTables), Duration.Inf))

Prints Vector() in console.


回答1:


Honestly have the same issue, wen't through a ton of posts and ideas what could be wrong and nothing worked, don't want to waste time on it so the easy way around it is to just have something like using sql directly:

db.run(sql"""show tables""".as[String]).onComplete({
  case scala.util.Success(value) => value.foreach(println)})

Which would return something like: city country countrylanguage I'm sure you could work it out how to use it from there.

p.s sorry for poor code example formatting




回答2:


The problem in my first case was invalid table structure.

The problem in my second case was invalid write permissions.

How to know the exact problem behind query failure:

Do this:

  val tables = List(Emails.emails)
  val setup = DBIO.sequence(
    tables.map(_.schema.create.asTry)
  )

  Await.result(db.run(setup).map(a => {
    println("/****\n\n\n\n\n\n\n\n\n\n\n\n\n")
    println(a)
    println("\n\n\n\n\n\n\n\n\n\n\n\n\n*************/")
  }), Duration.Inf)


来源:https://stackoverflow.com/questions/50516061/scala-slick-mtable-gettables-return-empty-vector-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!