Heroku 上的进化错误 [英] Errors in evolutions on Heroku

查看:20
本文介绍了Heroku 上的进化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试对 Heroku 进行一些改进:

I tried pushing some evolutions to Heroku:

2012-08-30T10:58:00+00:00 heroku[slugc]: Slug compilation finished
2012-08-30T10:58:02+00:00 heroku[web.1]: Starting process with command `target/start -Dhttp.port=32436 -Xmx384m -Xss512k
 -XX:+UseCompressedOops`
2012-08-30T10:58:03+00:00 app[web.1]: Play server process ID is 2
2012-08-30T10:58:05+00:00 app[web.1]: [←[37minfo←[0m] play - database [default] connected at [Database-address]
2012-08-30T10:58:05+00:00 app[web.1]: CREATE TABLE `unapprovedteaminfo` (
---
Copy of 1.sql
---
2012-08-30T10:58:05+00:00 app[web.1]: VALUES (1, 2, 2, '2012-01-01 00:00:00', 'k');
2012-08-30T10:58:05+00:00 app[web.1]: ERROR: syntax error at or near "`"
2012-08-30T10:58:05+00:00 app[web.1]:   Position: 14 [ERROR:0, SQLSTATE:42601]
2012-08-30T10:58:05+00:00 app[web.1]: Oops, cannot start the server.
2012-08-30T10:58:05+00:00 app[web.1]: PlayException: Database 'default' is in inconsistent state! [An evolution has not
been applied properly. Please check the problem and resolve it manually before marking it as resolved.]
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.db.evolutions.Evolutions$.checkEvolutionsState(Evolutions.scala:155)

2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.db.evolutions.Evolutions$.databaseEvolutions(Evolutions.scala:308)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.db.evolutions.Evolutions$.evolutionScript(Evolutions.scala:284)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.s
cala:412)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.s
cala:410)
2012-08-30T10:58:05+00:00 app[web.1]:   at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59
)
2012-08-30T10:58:05+00:00 app[web.1]:   at scala.collection.immutable.List.foreach(List.scala:45)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.db.evolutions.EvolutionsPlugin.onStart(Evolutions.scala:410)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.Play$$anonfun$start$1.apply(Play.scala:60)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.Play$$anonfun$start$1.apply(Play.scala:60)
2012-08-30T10:58:05+00:00 app[web.1]:   at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59
)
2012-08-30T10:58:05+00:00 app[web.1]:   at scala.collection.immutable.List.foreach(List.scala:45)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.Play$.start(Play.scala:60)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.core.StaticApplication.<init>(ApplicationProvider.scala:51)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.core.server.NettyServer$.createServer(NettyServer.scala:132)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.core.server.NettyServer$$anonfun$main$5.apply(NettyServer.scala:153)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.core.server.NettyServer$$anonfun$main$5.apply(NettyServer.scala:152)
2012-08-30T10:58:05+00:00 app[web.1]:   at scala.Option.map(Option.scala:133)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.core.server.NettyServer$.main(NettyServer.scala:152)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.core.server.NettyServer.main(NettyServer.scala)
2012-08-30T10:58:06+00:00 heroku[web.1]: Process exited with status 255
2012-08-30T10:58:06+00:00 heroku[web.1]: State changed from starting to crashed

这些演变在 H2 上工作得很好,我想 POSTGRESQL 语法肯定存在一些问题.无论如何,我现在遇到的问题是,即使我更改 1.sql 并在 Heroku 上推送新版本,日志中也会显示相同的错误 - 复制的 1.sql 不会根据新的推送版本更改.

These evolutions would work just fine with H2, I guess there must be some issues with POSTGRESQL syntax. Anyway, the problem I am having now is that, even if I change 1.sql and push the new version on Heroku, the same error will show up in the logs - the copied 1.sql does not change according to the new pushed version.

推荐答案

如果你发送给 Heroku 1.sqlH2 生成的文件,就有很大的机会他们会冲突,相反,将 application.conf 中的 Heroku url 设置为 db.default.url 并首先在本地主机上以开发模式运行它以生成有效的 Postres SQL.您还需要注释掉 db.default.userdb.default.password 设置,因为 Heroku 的 URL 已经包含此信息.

If you're sending to Heroku 1.sql file generated for H2, there is big chance that they will conflict, instead, set the Heroku's url in application.conf as db.default.url and run it in dev mode on localhost first to generate valid Postres SQL. Also you will need to comment out the db.default.user and db.default.password settings, as Heroku's URL contains this information already.

如果您不知道当前连接的 URL,您可以在以下位置找到它:

If you don't know current connection's URL you will find it on:

https://postgres.heroku.com/ -> YourDBs -> db-name -> 连接设置 -> JDBC URL

https://postgres.heroku.com/ -> YourDBs -> db-name -> Connection settings -> JDBC URL

要从本地主机(或其他机器,而不是在 Heroku 的空间中)连接,您需要将此参数添加到 URL:

To connect from localhost (or other machine, not in the Heroku's space) you need to add this param to the URL:

&ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory

多亏了这种方法,您可以通过与远程 Heroku 数据库建立的连接在本地测试您的应用程序,(不要感到惊讶 - 这种组合将比使用 本地应用程序 + 本地数据库 慢得多)或 Heroku app + Heroku DB) 无论如何测试它比反复将小修复程序推送到云中要好.

Thanks to this approach you can test your application locally with established connection to the remote Heroku's DB, (don't be surprised - that combination will be much slower than working with local app + local DB or Heroku app + Heroku DB) anyway for testing it's better than repeatedly pushing small fixes to the cloud.

此外,您还可以从 localhost 执行进化 - 无需将代码推送到 Heroku,如果您的 SQL 出现问题,这是一种更短的方法.

Also you'll be able to perform evolutions from localhost - without pushing the code to Heroku, and it's really shorter approach if you have problems in your SQL.

此外,这是在本地开发模式下打开 SQL 日志记录并寻找冗余 SQL 查询的好时机,如果您将删除所有不必要的查询并在 localhost 上感到满意,那么在部署到 Heroku 后,您将得到很多比较满意:)

Additionally it's good occasion to turn on SQL logging in local dev mode and hunt for redundant SQL queries, if you'll remove all not necessary queries and will be satisfied on localhost, after deploying to the Heroku, you will be just much more satisfied :)

如果您要创建正确的 1.sql 文件,那么您很可能需要重置包含无效结构的数据库(因为我认为这不是问题,因为您只是从本地移动到赫鲁克).首先找到当前应用程序的数据库名称(使用 bash,在应用程序的文件夹中):

If you'll create proper 1.sql file than most probably you'll need to reset your DB containing invalid structure (as I assume that's not a problem yet as you just moving from local to Heroku). First find a name of the DB for the current app (with bash, in app's folder):

heroku pg

然后将其重置(它会破坏所有数据,因此如果您不想丢失数据,请先考虑备份!):

And then reset it with (it will destroy all data so consider backup first if you don't want to loose your data!):

heroku pg:reset HEROKU_DATABASE_SOMEBASE

这篇关于Heroku 上的进化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆