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?

4

1 回答 1

1

我不知道确切的位置,但是您在不同的地方导入了不同的 Slick 驱动程序。当从他们那里拿走的文物混在一起时,你会得到SlickException: JdbcProfile has no TypeInfo for type Int/INTEGER.

于 2014-07-09T15:30:20.360 回答