【问题标题】:org.postgresql.util.PSQLException: ERROR: relation "bug_report_model" does not existorg.postgresql.util.PSQLException:错误:关系“bug_report_model”不存在
【发布时间】:2017-07-09 07:48:07
【问题描述】:

我正在尝试在 heroku 上运行一个简单的 java play 2.5 应用程序。我能够打开主页,这通常意味着与数据库的连接成功。但是,当我尝试调用路由以向表中添加一个虚拟值时,它会显示

play.api.UnexpectedException: Unexpected exception[PersistenceException: ERROR executing DML bindLog[] error[ERROR: relation "bug_report_model" does not exist\n   Position: 13]]

向数据库添加值的代码是

 public Result enterDummyTextInDb() {
    BugReportModel model = new BugReportModel();
    model.save();
    return ok(Json.toJson(model));
}

模型类是

@Entity
public class BugReportModel extends Model {
@Id
private Long id;
private Long timestamp = System.currentTimeMillis();

public BugReportModel() {
}

public static Finder<Long, BugReportModel> find = new Model.Finder<Long, BugReportModel>(BugReportModel.class);

public static List<BugReportModel> findAll() {
    return BugReportModel.find.orderBy("id").findList();
}


public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public Long getTimestamp() {
    return timestamp;
}

public void setTimestamp(Long timestamp) {
    this.timestamp = timestamp;
}

}

为 spring/hibernate 找到了一些东西,说该表没有创建,所以我们必须添加

spring.jpa.hibernate.ddl-auto=create 

但不确定是否适用于 java play 2.5

【问题讨论】:

  • 数据库中是否存在表“bug_report_model”?也许它被称为别的东西?
  • 数据库中现在没有表。就像我最后提到的那样。发现了一些与 spring/hibernate 相关的东西,但无法弄清楚如何在 java play 中创建数据库。在getting started scala play heroku code中发现了一些东西,但不知道如何在java中实现它

标签: java postgresql heroku playframework sbt


【解决方案1】:

您需要像这样创建 Procfile 来配置您的应用程序以运行进化:

web: target/universal/stage/bin/myapp -Dhttp.port=${PORT} -Dplay.evolutions.db.default.autoApply=true -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=${DATABASE_URL}

更多信息见https://www.playframework.com/documentation/2.5.x/ProductionHeroku

【讨论】:

    猜你喜欢
    • 2017-04-11
    • 2015-10-09
    • 2017-04-26
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多