3

在 Heroku 上使用 Play V2。在本地测试时一切正常,但是当我部署到 Heroku 并尝试保存到 PostgreSQL 数据库时,我收到以下错误。

在我的 Procfile 我有这个。

web: target/start -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.url=${DATABASE_URL} -Ddb.default.driver=org.postgresql.Driver

这是我的 Heroku 错误日志:

2012-04-03T18:16:05+00:00 app[web.1]: play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[PersistenceException: Error getting sequence nextval]]
2012-04-03T18:16:05+00:00 app[web.1]: ! @6a0gdoh95 - Internal server error, for request [POST /users] ->
2012-04-03T18:16:05+00:00 app[web.1]:   at play.core.ActionInvoker$$anonfun$receive$1.a

2012-04-03T18:16:05+00:00 app[web.1]: [error] application - 
2012-04-03T18:16:05+00:00 app[web.1]: 
2012-04-03T18:16:05+00:00 app[web.1]: 
2012-04-03T18:16:05+00:00 app[web.1]:   at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:63) [play_2.9.1-2.0.jar:2.0]
2012-04-03T18:16:05+00:00 app[web.1]:   at play.core.ActionInvoker.apply(Invoker.scala:61) [play_2.9.1-2.0.jar:2.0]
2012-04-03T18:16:05+00:00 app[web.1]:   at com.avaje.ebean.config.dbplatform.SequenceIdGenerator.loadMoreIds(SequenceIdGenerator.java:163) ~[ebean-2.7.3.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]:   at com.avaje.ebeaninternal.server.deploy.BeanDescriptor.nextId(BeanDescriptor.java:1218) ~[ebean-2.7.3.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]:   at com.avaje.ebean.config.dbplatform.SequenceIdGenerator.getMoreIds(SequenceIdGenerator.java:213) ~[ebean-2.7.3.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]:   at akka.actor.ActorCell.invoke(ActorCell.scala:617) [akka-actor-2.0.jar:2.0]
2012-04-03T18:16:05+00:00 app[web.1]:   at com.avaje.ebeaninternal.server.persist.DefaultPersister.setIdGenValue(DefaultPersister.java:1304) ~[ebean-2.7.3.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]:   at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:179) [akka-actor-2.0.jar:2.0]
2012-04-03T18:16:05+00:00 app[web.1]:   at akka.actor.Actor$class.apply(Actor.scala:290) [akka-actor-2.0.jar:2.0]
2012-04-03T18:16:05+00:00 app[web.1]:   at com.avaje.ebean.config.dbplatform.SequenceIdGenerator.nextId(SequenceIdGenerator.java:118) ~[ebean-2.7.3.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: Caused by: javax.persistence.PersistenceException: Error getting sequence nextval
2012-04-03T18:16:05+00:00 app[web.1]:   at com.avaje.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:403) ~[ebean-2.7.3.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]:   at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1810) ~[postgresql-8.4-702.jdbc4.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]:   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271) ~[postgresql-8.4-702.jdbc4.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]:   at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2077) ~[postgresql-8.4-702.jdbc4.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]:   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386) ~[postgresql-8.4-702.jdbc4.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: Caused by: org.postgresql.util.PSQLException: ERROR: relation "user_seq" does not exist
2012-04-03T18:16:05+00:00 app[web.1]:   at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) ~[postgresql-8.4-702.jdbc4.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]:   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:498) ~[postgresql-8.4-702.jdbc4.jar:na]
4

2 回答 2

2

2012-04-03T18:16:05+00:00 app[web.1]: Caused by: org.postgresql.util.PSQLException: ERROR: relation "user_seq" does not exist

似乎表明您的数据库缺少一些表。确保您的架构是正确的。您可以使用heroku pg:psql.

一个好的做法是从头开始在本地设置 postgres,并确保执行此操作的所有步骤都由您的应用程序或脚本自动执行,这样就更难忘记这样的事情。

于 2013-03-27T21:40:59.497 回答
0

我已经描述了下面的 ID 列并传递了错误。

@Id
@SequenceGenerator(name = "UserSequence", sequenceName = "\"USER_SEQ\"", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "UserSequence")
@Column(name = "\"USER_ID\"")
Long userId;
于 2022-03-01T20:22:02.507 回答