Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play evolutions throwing error when trying to run it for the first time #600

Open
ashwinreal opened this issue Jul 13, 2021 · 10 comments
Open

Comments

@ashwinreal
Copy link

ashwinreal commented Jul 13, 2021

Error: [PSQLException: ERROR: relation "play_evolutions" does not exist Position: 8].
I can see the table play_evolutions in the db. Play does create this table on starting the server.

{"timestamp":"2021-07-13T08:40:29.320Z","level":"ERROR","thread":"play-dev-mode-akka.actor.default-dispatcher-7","logger":"play.api.http.DefaultHttpErrorHandler","message":"

! @7kc2k4hep - Internal server error, for (GET) [/] ->
 ","context":"default","exception":"play.api.PlayException: Execution exception[[PSQLException: ERROR: relation "play_evolutions" does not exist
  Position: 51]]
	at play.api.http.HttpErrorHandlerExceptions$.$anonfun$convertToPlayException$3(HttpErrorHandler.scala:388)
	at scala.Option.getOrElse(Option.scala:202)
	at play.api.http.HttpErrorHandlerExceptions$.convertToPlayException(HttpErrorHandler.scala:388)
	at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:373)
	at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:264)
	at play.core.server.Server$$anonfun$handleErrors$1$1.applyOrElse(Server.scala:109)
	at play.core.server.Server$$anonfun$handleErrors$1$1.applyOrElse(Server.scala:105)
	at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:37)
	at play.core.server.Server$.getHandlerFor(Server.scala:129)
	at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:317)
	at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:224)
	at akka.stream.impl.fusing.MapAsync$$anon$30.onPush(Ops.scala:1297)
	at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:541)
	at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:495)
	at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:390)
	at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:625)
	at akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:502)
	at akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:600)
	at akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:775)
	at akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:790)
	at akka.actor.Actor.aroundReceive(Actor.scala:537)
	at akka.actor.Actor.aroundReceive$(Actor.scala:535)
	at akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:691)
	at akka.actor.ActorCell.receiveMessage(ActorCell.scala:579)
	at akka.actor.ActorCell.invoke(ActorCell.scala:547)
	at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:270)
	at akka.dispatch.Mailbox.run(Mailbox.scala:231)
	at akka.dispatch.Mailbox.exec(Mailbox.scala:243)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175)
Caused by: org.postgresql.util.PSQLException: ERROR: relation "play_evolutions" does not exist
  Position: 51
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:473)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:393)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:322)
	at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:308)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:284)
	at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:236)
	at com.zaxxer.hikari.pool.ProxyStatement.executeQuery(ProxyStatement.java:111)
	at com.zaxxer.hikari.pool.HikariProxyStatement.executeQuery(HikariProxyStatement.java)
	at play.api.db.evolutions.DatabaseEvolutions.executeQuery(EvolutionsApi.scala:336)
	at play.api.db.evolutions.DatabaseEvolutions.databaseEvolutions(EvolutionsApi.scala:146)
	at play.api.db.evolutions.DatabaseEvolutions.scripts(EvolutionsApi.scala:118)
	at play.api.db.evolutions.DatabaseEvolutions.scripts(EvolutionsApi.scala:133)
	at play.api.db.evolutions.DefaultEvolutionsApi.scripts(EvolutionsApi.scala:98)
	at play.api.db.evolutions.ApplicationEvolutions$.$anonfun$runEvolutions$1(ApplicationEvolutions.scala:205)
	at play.api.db.evolutions.ApplicationEvolutions$.withLock(ApplicationEvolutions.scala:231)
	at play.api.db.evolutions.ApplicationEvolutions$.runEvolutions(ApplicationEvolutions.scala:201)
	at play.api.db.evolutions.EvolutionsWebCommands.$anonfun$handleWebCommand$4(ApplicationEvolutions.scala:517)
	at play.api.db.evolutions.EvolutionsWebCommands.$anonfun$handleWebCommand$4$adapted(ApplicationEvolutions.scala:512)
	at scala.collection.immutable.List.foreach(List.scala:312)
	at play.api.db.evolutions.EvolutionsWebCommands.handleWebCommand(ApplicationEvolutions.scala:512)
	at play.core.DefaultWebCommands.$anonfun$handleWebCommand$1(WebCommands.scala:42)
	at scala.collection.immutable.Stream.flatMap(Stream.scala:195)
	at play.core.DefaultWebCommands.handleWebCommand(WebCommands.scala:42)
	at play.api.http.DefaultHttpRequestHandler.$anonfun$handlerForRequest$4(HttpRequestHandler.scala:223)
	at scala.Option.flatMap(Option.scala:284)
	at play.api.http.DefaultHttpRequestHandler.handlerForRequest(HttpRequestHandler.scala:222)
	at play.core.server.Server$.getHandlerFor(Server.scala:126)
	... 23 common frames omitted
"}
@ashwinreal
Copy link
Author

ashwinreal commented Jul 13, 2021

This is the configuration that I am using,

slick.dbs {
    default {
        profile = "slick.jdbc.PostgresProfile$"
        db.driver = "org.postgresql.Driver"
        db.url = "jdbc:postgresql://localhost:5432/new_db"
        db.user = "name"
        db.password = ""
    }
}

and this is the build.sbt

import play.sbt.PlayImport
lazy val root = (project in file("."))
  .enablePlugins(PlayScala)
  .settings(
    name := """Us Stocks""",
    version := "0.0.1",
    scalaVersion := "2.13.0",
    libraryDependencies ++= Seq(
      guice,
      "com.typesafe.play" %% "play-slick" % "5.0.0",
      "com.typesafe.play" %% "play-slick-evolutions" % "5.0.0",
      "org.postgresql" % "postgresql" % "42.2.18",
      "mysql" % "mysql-connector-java" % "8.0.23",
      "com.typesafe.slick" %% "slick-codegen" % "3.3.3",
      "org.json4s" %% "json4s-jackson" % "3.6.6",
      "com.typesafe.play" %% "play-ws" % "2.8.7",
      "com.typesafe.play" %% "play-ahc-ws-standalone" % "2.1.2",
      "com.amazonaws" % "aws-java-sdk-sqs" % "1.11.969",
      "ai.x" %% "play-json-extensions" % "0.42.0",
      "com.dripower" %% "play-circe" % "2812.0",
      "io.circe" %% "circe-generic" % "0.14.0-M4",
      "com.newrelic.agent.java" % "newrelic-api" % "6.4.2",
      "com.amazonaws" % "aws-java-sdk-sqs" % "1.11.969",
      "com.pusher" %  "pusher-java-client" % "2.2.6",
      "redis.clients" %  "jedis" % "3.1.0",
      "org.redisson" %  "redisson" % "3.13.1",
      "net.liftweb" %  "lift-json_2.13" % "3.4.3",
      "com.lihaoyi" %  "os-lib_3" % "0.7.8",
      "ch.qos.logback" % "logback-classic" % "1.2.3",
      "ch.qos.logback.contrib" % "logback-jackson" % "0.1.5",
      "ch.qos.logback.contrib" % "logback-json-classic" % "0.1.5",
      "com.fasterxml.jackson.core" % "jackson-databind" % "2.9.5",
      "org.scanamo" %% "scanamo" % "1.0.0-M15" exclude("com.fasterxml.jackson.core","jackson-databind"),
      "software.amazon.awssdk" % "dynamodb" % "2.16.68" exclude("com.fasterxml.jackson.core","jackson-databind"),
      specs2 % Test
    )
  )
    libraryDependencies += ws

@Max-AR
Copy link
Member

Max-AR commented Apr 5, 2022

I have also experienced this error and this was my resolution:

https://stackoverflow.com/questions/59701024/cannot-create-play-evolutions-table

A basic config to postgres and like the stackoverflow user, changing from 2 threads to 10 threads cleared the issue.

@mkurz
Copy link
Member

mkurz commented Apr 6, 2022

Not sure what the original problem really is about, but just guessing, could it be that a play-slick component needs to depend on (inject) the ApplicationEvolutions, to make sure evolutions runs before play-slick kicks in? It might also make sense to check for applicationEvolutions.upToDate to see if evolutions are correctly applied before play-slick starts to do its thing.
EDIT: More info can be found here: https://www.playframework.com/documentation/2.8.x/Migration27#Application-starts-when-evolutions-scripts-need-to-be-applied-in-DEV-mode

@mkurz
Copy link
Member

mkurz commented Apr 6, 2022

I had a look and think having DefaultSlickApi also inject ApplicationEvolutions should help fixing the problem:

final class DefaultSlickApi @Inject() (
environment: Environment,
configuration: Configuration,
lifecycle: ApplicationLifecycle
)(implicit executionContext: ExecutionContext)

@nemoo
Copy link
Contributor

nemoo commented Sep 14, 2023

I have also experienced this error and this was my resolution:

https://stackoverflow.com/questions/59701024/cannot-create-play-evolutions-table

A basic config to postgres and like the stackoverflow user, changing from 2 threads to 10 threads cleared the issue.

for me, the workaround of changing the number of threads did not work.

@nemoo
Copy link
Contributor

nemoo commented Sep 14, 2023

I had a look and think having DefaultSlickApi also inject ApplicationEvolutions should help fixing the problem:

final class DefaultSlickApi @Inject() (
environment: Environment,
configuration: Configuration,
lifecycle: ApplicationLifecycle
)(implicit executionContext: ExecutionContext)

so I guess to try this I would have to build play framework myself?

@mkurz
Copy link
Member

mkurz commented Sep 14, 2023

@nemoo No not Play, but "only" play-slick. Just check out the repo, apply the fix and run sbt +publishLocal, you will see which version will be generated and use that version in your app and give it a try.

@nemoo
Copy link
Contributor

nemoo commented Sep 14, 2023

edit: got it to compile (without the new injection) by adding,

dependencyOverrides += "org.scala-lang.modules" % "scala-xml_2.13" % "2.1.0"
dependencyOverrides += "com.typesafe.slick" % "slick_2.13" % "3.4.1"

now off to testing


ok I might need some help with that.
I changed my play 2.8.16 apps dependencies to include the custom built play-slick ( I just built the main branch):

//libraryDependencies += "com.typesafe.play" %% "play-slick" % "5.1.0"
libraryDependencies += "com.typesafe.play" %% "play-slick" % "5.2.0-M3+34-9a91c3f5+20230914-0924-SNAPSHOT"
libraryDependencies += "com.typesafe.play" %% "play-slick-evolutions" % "5.1.0"
libraryDependencies += "com.typesafe.play" %% "play-json" % "2.9.2"
libraryDependencies += "com.github.takezoe" %% "blocking-slick" % "0.0.14"
libraryDependencies += guice
libraryDependencies += ws
libraryDependencies += caffeine
libraryDependencies += "joda-time" % "joda-time" % "2.3"
libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.10"
libraryDependencies += "org.tmatesoft.svnkit" % "svnkit" % "1.9.0"
libraryDependencies += "org.apache.commons" % "commons-email" % "1.3.1"
libraryDependencies += "com.unboundid" % "unboundid-ldapsdk" % "2.3.1"
//libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.28"
libraryDependencies += "org.postgresql" % "postgresql" % "42.3.2"
libraryDependencies += "io.github.honeycomb-cheesecake" %% "play-silhouette" % "7.0.2"
libraryDependencies += "io.github.honeycomb-cheesecake" %% "play-silhouette-password-bcrypt" % "7.0.2"
libraryDependencies += "io.github.honeycomb-cheesecake" %% "play-silhouette-persistence" % "7.0.2"
libraryDependencies += "io.github.honeycomb-cheesecake" %% "play-silhouette-crypto-jca" % "7.0.2"
libraryDependencies += "net.codingwell" %% "scala-guice" % "4.2.6"
libraryDependencies += "com.iheart" %% "ficus" % "1.4.7"
libraryDependencies += "org.scalaj" %% "scalaj-http" % "2.4.2"
libraryDependencies += "org.webjars" % "bootstrap" % "5.1.3"
libraryDependencies += "org.webjars.npm" % "bootstrap-icons" % "1.10.5"
libraryDependencies += "org.webjars" % "popper.js" % "2.9.3"
libraryDependencies += "org.webjars" % "jquery" % "3.5.1"
libraryDependencies += "org.webjars" % "momentjs" % "2.24.0"
libraryDependencies += "de.siegmar" % "logback-gelf" % "1.0.4"
libraryDependencies += "com.lihaoyi" %% "os-lib" % "0.4.2"
libraryDependencies += "com.lihaoyi" %% "upickle" % "0.8.0"
libraryDependencies += "com.lihaoyi" %% "pprint" % "0.5.6"
libraryDependencies += "com.lihaoyi" %% "scalatags" % "0.8.2"
libraryDependencies += "io.prometheus" % "simpleclient" % "0.10.0"
libraryDependencies += "io.prometheus" % "simpleclient_hotspot" % "0.10.0"
libraryDependencies += "io.prometheus" % "simpleclient_servlet" % "0.10.0"

When starting play, I now get those version conflicts below. How would I tackle those?

error] java.lang.RuntimeException: found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
[error] 
[error] 	* org.scala-lang.modules:scala-xml_2.13:2.1.0 (early-semver) is selected over 1.2.0
[error] 	    +- com.typesafe.play:twirl-api_2.13:1.5.1             (depends on 2.1.0)
[error] 	    +- com.typesafe.play:play-ws-standalone-xml_2.13:2.1.10 (depends on 1.2.0)
[error] 
[error] 	* com.typesafe.slick:slick_2.13:3.5.0-M4 (pvp) is selected over 3.4.1
[error] 	    +- com.typesafe.play:play-slick_2.13:5.2.0-M3+34-9a91c3f5+20230914-0924-SNAPSHOT (depends on 3.5.0-M4)
[error] 	    +- com.typesafe.slick:slick-hikaricp_2.13:3.5.0-M4    (depends on 3.5.0-M4)
[error] 	    +- com.github.takezoe:blocking-slick_2.13:0.0.14      (depends on 3.4.1)
[error] 

@nemoo
Copy link
Contributor

nemoo commented Sep 14, 2023

Ok I am struggling to import ApplicationEnvolutions in the play-slick SlickApi.scala File.

I tried it with:
import play.api.db.evolutions.ApplicationEvolutions

which gives me:

[error] /home/xxx/git/play-slick/src/core/src/main/scala/play/api/db/slick/SlickApi.scala:13:20: object evolutions is not a member of package play.api.db

[error] import play.api.db.evolutions.ApplicationEvolutions

play slick core Dependencies do not include play-jdbc-evolutions, therefore ApplicationEvolutions is not visible:
https://github.com/playframework/play-slick/blob/main/project/Dependencies.scala#L5-L11

@nemoo
Copy link
Contributor

nemoo commented Sep 27, 2023

Update:
@mkurz I now tried to implement your suggestion on the 5.1.x branch, to narrow it down.
See my changes here: https://github.com/playframework/play-slick/compare/5.1.x...nemoo:play-slick:5.1.x?expand=1 (can turn into a pr if that is more helpful)

When I try to use this build in my play app, I now get this error:

lay.api.UnexpectedException: Unexpected exception[CreationException: Unable to create injector, see the following errors:
1) Found a circular dependency involving play.api.db.slick.SlickApi, and circular dependencies are disabled.
  while locating play.api.db.slick.DefaultSlickApi
  at play.api.db.slick.SlickModule.bindings(SlickModule.scala:40):
Binding(interface play.api.db.slick.SlickApi to ConstructionTarget(class play.api.db.slick.DefaultSlickApi) in interface javax.inject.Singleton) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$4)
  while locating play.api.db.slick.SlickApi
    for the 1st parameter of play.api.db.slick.evolutions.internal.DBApiAdapter.<init>(DBApiAdapter.scala:21)
  while locating play.api.db.slick.evolutions.internal.DBApiAdapter
  at play.api.db.slick.evolutions.EvolutionsModule.bindings(EvolutionsModule.scala:15):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants