我正在使用 Play Framework (1.2.4) 我创建了一个 UserAccount
对象,并将其部署到 Heroku。效果很好。然后我向 UserAccount
类添加了一个 isAdmin
字段,将其部署在本地并且运行良好(但我使用的是内存数据库),然后我将其部署到Heroku,现在我得到以下异常:
2011-12-23T09:03:35+00:00 app[web.1]: play.exceptions.JavaExecutionException: org.hibernate.exception.SQLGrammarException: could not load an entity: [models.UserAccount#2]
2011-12-23T09:03:35+00:00 app[web.1]: PersistenceException occured : org.hibernate.exception.SQLGrammarException: could not load an entity: [models.UserAccount#2]
...
2011-12-23T09:03:35+00:00 app[web.1]: Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not load an entity: [models.UserAccount#2]
2011-12-23T09:03:35+00:00 app[web.1]: Caused by: org.hibernate.exception.SQLGrammarException: could not load an entity: [models.UserAccount#2]
2011-12-23T09:03:35+00:00 app[web.1]: Caused by: org.postgresql.util.PSQLException: ERROR: column useraccoun0_.isadmin does not exist
...
我四处搜索以弄清楚如何进行数据库升级,Play 网站说 Hibernate 应该为我处理这个问题。
这是我的数据库属性:
%prod.db=${DATABASE_URL}
%prod.jpa.dialect=org.hibernate.dialect.PostgreSQLDialect
%prod.jpa.ddl=update
我做错了什么?感谢您的帮助。
最佳答案
在 Prod 模式下,属性 jpa.ddl 应该是 none。更新在生产中是有风险的,因为它可能会破坏数据库(因为它似乎发生在你身上!
管理此问题的正确方法是:
- 在您的 Heroku 应用程序上安装 Heroku SQL 控制台(来自 here)
- 将 jpa.ddl 更改为 none
- 使用 SQL 控制台连接到您的 heroku 数据库并应用您必须的任何修复/更新
- 将应用程序重新上传到 Heroku(记得在本地进行新的提交,否则 Heroku 会说代码已经是最新的)
这应该有效。
关于java - 使用 Heroku 升级 Play Framework DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8614127/