Configuring a Postgresql connection with Play 2 and Slick-Play

5.5k views Asked by At

I'm learning how to build an application using Scala and the Play 2 Framemork. I`ve created a new project using the activator tool, based on "play-scala-intro" current template.

The template have a sample app using the Play-Slick 1.0 for managing dependencies and is configured with a H2 DB, that worked without problems.

When I tried to change to a Postgres DB, I'm running in trouble. I get an error 500, telling me:

"Cannot connect to database [default]".

In the stack trace, the exception is:

"Configured Slick driver org.postgresql.Driver is not an instance of requested profile slick.profile.BasicProfile"

So... What I already did:

I added to my build.sbt file the dependency:

"org.postgresql" % "postgresql" % "9.4-1201-jdbc41"

In my configuration file (application.conf), the DB connection is configured as:

slick.dbs.default.driver=org.postgresql.Driver slick.dbs.default.db.url="jdbc:postgresql://localhost:5432/hello_play" slick.dbs.default.db.user="postgres" slick.dbs.default.db.password=""

PS: I've tried with slick.dbs.default.driver="org.postgresql.Driver" too...

PS2: My db password is empty. I'm connecting with PgAdmin without problems

1

There are 1 answers

0
Roman On BEST ANSWER

slick.dbs.default.driver must be a slick driver, not a JDBC driver. Your db config should look something like this:

slick.dbs.default.driver="slick.driver.PostgresDriver$"
slick.dbs.default.db.driver="org.postgresql.Driver"
slick.dbs.default.db.url="jdbc:postgresql://localhost:5432/hello_play"
slick.dbs.default.db.user="postgres"
slick.dbs.default.db.password=""