Heroku的演变错误 [英] Errors in evolutions on Heroku

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

问题描述

我试图推动Heroku的一些发展:

  2012-08-30T10:58:00 + 00:00 heroku [ slugc]:Slug编译完成
2012-08-30T10:58:02 + 00:00 heroku [web.1]:用命令`target / start -Dhttp.port = 32436 -Xmx384m -Xss512k $ b启动进程$ b -XX:+ UseCompressedOops`
2012-08-30T10:58:03 + 00:00 app [web.1]:Play服务器进程ID为2
2012-08-30T10:58: 05 + 00:00 app [web.1]:[←[37minfo←[0m] play - database [default]连接在[Database-address]
2012-08-30T10:58:05 + 00:00应用[web.1]:CREATE TABLE`unapprovedteaminfo`(
---
)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]:错误:语法错误处于或附近`
2012-08-30T10:58:05 + 00:00 app [web.1]:位置:14 [错误: 0,SQLSTATE:42601]
2012-08-30T10:58:05 + 00:00 app [web.1]:糟糕,无法启动服务器
2012-08-30T10:58:05 +00:00应用[web.1]:PlayException:Datab ase'default'处于不一致的状态! [一个进化没有正确应用
。请检查问题并解决问题,然后将其标记为已解决。]
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]:在play.api.db.evolutions.EvolutionsPlugin.onStart(Evolutions.scala:410)
2012-08-30T10:58:05 + 00:00 app [web .1]:在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]:在play.core.server.NettyServer $ .createServer(NettyServer.scala:132)
2012-08-30T10:58:05 + 00:00 app [web .1]:在play.core.server.NettyServer $$ anonfun $ main $ 5.apply(NettyServer.scala:153)
2012-08-30T10:58:05 + 00:00 app [web.1]:在play.core.server.NettyServer $$ anonfun $ main $ 5.apply(NettyServer.scala:152)
2012-08-30T10:58:05 + 00:00 app [web .1]:在scala.Option.map(Option.scala:133)
2012-08-30T10:58:05 + 00:00 app [web.1]:在play.core.server.NettyServer $ .main(NettyServer.scala:152)
2012-08-30T10:58:05 + 00:00 app [web.1]:在play.core.server.NettyServer.main(NettyServer.scala)
2012-08-30T10:58:06 + 00:00 heroku [web.1]:进程退出状态255
2012-08-30T10:58:06 + 00:00 heroku [web.1] :状态从开始变为崩溃

这些演变对H2很有用,我想必须有POSTGRESQL语法存在一些问题。无论如何,我现在遇到的问题是,即使我更改了1.sql并在Heroku上推送新版本,也会在日志中显示相同的错误 - 复制的1.sql不会根据新的推送版本而改变如果你发送到Heroku 1.sql 文件 H2 生成,它们很有可能会发生冲突,相反,将Heroku的url设置为 application.conf db.default.url 并首先在本地主机上以开发模式运行它以生成有效的Postres SQL。您还需要注释 db.default.user db.default.password 设置,因为Heroku的URL包含这些信息。



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



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

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

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

感谢这种方法,您可以在本地测试您的应用程序,并建立与远程Heroku数据库的连接(不要惊讶 - 与使用本地应用程序+本地数据库 Heroku应用程序+ Heroku DB )a对于测试而言,要比反复将小修补程序推向云计算更好。



您也可以从localhost执行演化 - 不需要将代码推送到Heroku,而且如果您的SQL出现问题,这种方法实际上会更短。



此外,在本地开发模式下打开SQL日志记录并寻找冗余SQL查询是一个很好的机会,如果您将删除所有不必要的查询,并且在部署后会在本地主机上满足到Heroku,你会更加满意:)

重置



如果你要创建适当的 1.sql 文件比大多数情况下您需要重置包含无效结构的数据库(因为我认为从刚刚从本地移动到Heroku时这不是问题)。首先找到当前应用程序数据库的名称(使用bash,在应用程序文件夹中):

  heroku pg 

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

  heroku pg:reset HEROKU_DATABASE_SOMEBASE 


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

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.

解决方案

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.

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

https://postgres.heroku.com/ -> YourDBs -> db-name -> Connection settings -> JDBC 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

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.

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.

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 :)

Reset

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天全站免登陆