org.postgresql.util.PSQLException:错误:关系“bug_report_model”不存在

时间:2017-07-09 07:48:08

标签: java postgresql heroku playframework sbt

我正在尝试在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));
}

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

不确定

1 个答案:

答案 0 :(得分:0)

您需要通过制作这样的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