3

Background

  • Play 2.3
  • Slick 2.1
  • Play-Slick 0.7
  • Running in Typesafe Activator

I have a pretty basic Play and Slick-based application. Up to now I've been using the in-memory h2 database used by default in most of the examples.

In application.conf I have the following lines:

db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"

If I use

import play.api.db.slick.Config.driver.simple._

for any code which interacts with the database, the application knows to pull in the defines in application.conf and the following happens when I run my application:

  • evolutions.default/1.sql is created
  • a new h2 database is instantiated in memory
  • 1.sql is run on that db
  • the application can interact with the db

Problem

I want to migrate to using a Postgres db, so I've changed application.conf to:

db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/testdb"
db.default.user=testuser

and I've added the following to my build.sbt

libraryDependencies ++= Seq(
  ...
  "org.postgresql" % "postgresql" % "9.3-1100-jdbc4"
)

However, if I write a test like the following:

import models._
import org.specs2.mutable.Specification
import play.api.db.slick.Config.driver.simple._
import play.api.db.slick.DB
import scala.language.reflectiveCalls
import play.api.test.{FakeApplication, WithApplication}

class FooSpec extends Specification {    
  "DB" should {    
    "store Foos" in new WithApplication {    
      val foos = TableQuery[FooTable]    
      DB.withSession { implicit s: Session =>
        foos.insert(Foo("bar"))
      }
    }
  }
}

I get a few errors which I don't understand:

[error] p.a.d.s.d.TableScanner$ - Got an error converting to DDL. Check whether the profile used for the Table/TableQuery is the same one used by DDL generation.

[info] foospec

[info] DB should

[info] ! store Foos

[error] SlickException: JdbcProfile has no TypeInfo for type Int/INTEGER

(I have a stack trace for the error if needed, but I've left it out for now)

Any idea what I've done wrong?

Community
  • 1
  • 1
sam-w
  • 7,478
  • 1
  • 47
  • 77

1 Answers1

1

I don't know exactly where, but you are importing different Slick drivers in different places. When artifacts taken from them get mixed up you get SlickException: JdbcProfile has no TypeInfo for type Int/INTEGER.

cvogt
  • 11,260
  • 30
  • 46
  • You were correct - although I wasn't actually referencing the old .scala file which imported the different database driver, it was still being imported into my test, hence this problem. Thanks for the pointer. – sam-w Jul 09 '14 at 23:17