gpt4 book ai didi

playframework - 转换为 postgres 时出错

转载 作者:行者123 更新时间:2023-12-02 03:34:21 25 4
gpt4 key购买 nike

背景

  • Play 2.3
  • 流畅 2.1
  • 流畅 0.7
  • 在 Typesafe Activator 中运行

我有一个非常基本的基于 Play 和 Slick 的应用程序。到目前为止,我一直在使用大多数示例中默认使用的内存中 h2 数据库。

application.conf 中,我有以下几行:

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

如果我用

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

对于与数据库交互的任何代码,应用程序知道在 application.conf 中引入定义,当我运行我的应用程序时会发生以下情况:

  • 创建了 evolutions.default/1.sql
  • 在内存中实例化了一个新的h2数据库
  • 1.sql 在该数据库上运行
  • 应用程序可以与数据库交互

问题

我想迁移到使用 Postgres 数据库,所以我将 application.conf 更改为:

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

并且我已将以下内容添加到我的 build.sbt

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

但是,如果我编写如下测试:

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"))
}
}
}
}

我遇到了一些我不理解的错误:

[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

(如果需要,我有一个错误的堆栈跟踪,但我现在把它留了下来)

知道我做错了什么吗?

最佳答案

我不知道确切的位置,但您在不同的地方导入了不同的 Slick 驱动程序。当从它们中获取的工件混淆时,您会得到 SlickException: JdbcProfile has no TypeInfo for type Int/INTEGER

关于playframework - 转换为 postgres 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24646315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com