Search code examples
scalaslickplayframework-2.4slick-3.0

Upgrading Play to 2.4, Slick to 3.1.1, value withTransaction is not a member of play.api.db.slick.Database


I am trying to upgrade my application from using Play 2.3.x to Play 2.4.x (will end at 2.6, but going one step at a time) and Slick from 2.1.0 to 3.1.1.

I have done my best to follow Play's migration guide, the Play Slick migration guide, and the Slick upgrade guides.

One of the problems I'm having right now is with the following line:

val db: slick.Database = play.api.db.slick.DB

This no longer seems to be the correct way to do this b/c I get errors like:

value withTransaction is not a member of play.api.db.slick.Database

From the Play slick migration guide, it seems like I should modify this to something like

val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)

But idk if I just don't have the right imports or what, but I get errors like:

object driver is not a member of package play.api.db.slick
not found: value DatabaseConfigProvider

For more context, here is one of the files I'm working with that gives this error: https://github.com/ProjectSidewalk/SidewalkWebpage/blob/2c48dfa2e34c691e40568bfa9d50493aa3fe9971/app/models/attribute/GlobalAttributeTable.scala

Anyone know what I missed among these migration guides?

Thank you in advance!


Solution

  • Turns out that I was missing a few things:

    1. I had not realized that I needed to use a more recent version of the play-slick library (I was using 0.8.0 still instead of 1.1.1).
    2. I needed to add the import import play.api.Play instead of the import import play.api.Play.current that I already had.
    3. I had an import import play.api.db.slick that was causing the "object driver is not a member of package play.api.db.slick" error at the line with this import: import slick.driver.JdbcProfile. I just removed the former import that was not needed.
    4. As @Valerii said, withTransaction has been removed in Slick 3.1, and the replacement is documented in the various links in the comments above.