2012-06-28 54 views
5

我想通過玩框架應用程序在heroku上設置postgres數據庫,但我不斷收到有關我的DATABASE_URL的錯誤。Heroku - 無法通過Play Framework應用程序設置postgres數據庫?

堆棧跟蹤: - :

echo "export DATABASE_URL=postgres://postgres:[email protected]/Play">>.bash_profile 
. .bash_profile 

我試圖設置另一個URL以及,我發現使用命令heroku config -

-----> Heroku receiving push 
-----> Play 2.0 - Java app detected 
-----> Running: sbt clean compile stage 
     Getting net.java.dev.jna jna 3.2.3 ... 
     :: retrieving :: org.scala-sbt#boot-jna 
     confs: [default] 
     1 artifacts copied, 0 already retrieved (838kB/25ms) 
     Getting org.scala-tools.sbt sbt_2.9.1 0.11.2 ... 
     :: retrieving :: org.scala-sbt#boot-app 
     confs: [default] 
     37 artifacts copied, 0 already retrieved (7324kB/78ms) 
     Getting Scala 2.9.1 (for sbt)... 
     :: retrieving :: org.scala-sbt#boot-scala 
     confs: [default] 
     4 artifacts copied, 0 already retrieved (19939kB/188ms) 
     [info] Loading global plugins from /tmp/build_hdhsg4dgyxy/.sbt_home/.sbt/plugins 
     [info] Updating {file:/tmp/build_hdhsg4dgyxy/.sbt_home/.sbt/plugins/}default-05c586... 
     [info] Resolving org.scala-tools.sbt#sbt_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#main_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#actions_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#classfile_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#io_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#control_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-lang#scala-library;2.9.1 ... 
     [info] Resolving org.scala-tools.sbt#interface;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#logging_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#process_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#classpath_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#launcher-interface_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-lang#scala-compiler;2.9.1 ... 
     [info] Resolving org.scala-tools.sbt#incremental-compiler_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#collections_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#api_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#persist_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbinary#sbinary_2.9.0;0.4.0 ... 
     [info] Resolving org.scala-tools.sbt#compile_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#ivy_2.9.1;0.11.2 ... 
     [info] Resolving org.apache.ivy#ivy;2.2.0 ... 
     [info] Resolving com.jcraft#jsch;0.1.31 ... 
     [info] Resolving commons-httpclient#commons-httpclient;3.1 ... 
     [info] Resolving commons-logging#commons-logging;1.0.4 ... 
     [info] Resolving commons-codec#commons-codec;1.2 ... 
     [info] Resolving org.scala-tools.sbt#completion_2.9.1;0.11.2 ... 
     [info] Resolving jline#jline;0.9.94 ... 
     [info] Resolving org.scala-tools.sbt#run_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#task-system_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#tasks_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#tracking_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#cache_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#testing_2.9.1;0.11.2 ... 
     [info] Resolving org.scala-tools.testing#test-interface;0.5 ... 
     [info] Resolving org.scala-tools.sbt#compiler-interface;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#precompiled-2_8_1;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#precompiled-2_8_0;0.11.2 ... 
     [info] Resolving org.scala-tools.sbt#precompiled-2_9_0;0.11.2 ... 
     [info] Done updating. 
     [info] Compiling 1 Scala source to /tmp/build_hdhsg4dgyxy/.sbt_home/.sbt/plugins/target/scala-2.9.1/sbt-0.11.2/classes... 
     [info] Loading project definition from /tmp/build_hdhsg4dgyxy/project 
     [info] Set current project to PostDemo (in build file:/tmp/build_hdhsg4dgyxy/) 
     [success] Total time: 0 s, completed Jun 28, 2012 2:20:47 AM 
     [info] Updating {file:/tmp/build_hdhsg4dgyxy/}PostDemo... 
[info] downloading http://repo.typesafe.com/typesafe/releases/postgresql/postgresql/9.1-901.jdbc4/postgresql-9.1-901.jdbc4.jar ... 
     [info] [SUCCESSFUL ] postgresql#postgresql;9.1-901.jdbc4!postgresql.jar (117ms) 
     [info] Done updating. 
     [info] Compiling 4 Scala sources and 4 Java sources to /tmp/build_hdhsg4dgyxy/target/scala-2.9.1/classes... 
     [error] {file:/tmp/build_hdhsg4dgyxy/}PostDemo/compile:compile: com.typesafe.config.ConfigException$UnresolvedSubstitution: conf/application.conf: 37: Could not resolve substitution to a value: ${DATABASE_URL} 
     [error] Total time: 10 s, completed Jun 28, 2012 2:20:57 AM 
!  Failed to build app with sbt 
!  Heroku push rejected, failed to compile Play 2.0 - java app 
     error: failed to push some refs to '[email protected]' 

我使用下面的命令來設置我的DATABASE_URL作爲環境變量我所知道的是一個很長的postgres網址,但它並沒有起作用,每次都出現同樣的異常。

以下是我在application.conf文件添加

%prod.db=${DATABASE_URL} 

依賴

val appDependencies = Seq(
    "postgresql" % "postgresql" % "9.1-901.jdbc4" 
) 

所以現在我感到困惑的我DATABASE_URL。爲什麼heroku無法用合適的價值取代它。 heroku在哪裏尋找合適的URL?在我的application.conf文件中或在我係統的bash配置文件中設置的環境變量中?

任何幫助將非常感激。

感謝

編輯

日誌

2012-06-28 20:38:18,500 - [INFO] - from play in main 
Listening for HTTP on port 9000... 

2012-06-28 20:38:25,862 - [INFO] - from play in play-akka.actor.default-dispatcher-1 
database [default] connected at jdbc:postgresql://localhost/Play 

2012-06-28 20:38:27,470 - [ERROR] - from application in New I/O server worker #1-1 


! @6aoffk4jk - Internal server error, for request [GET /login/?username=abc&&password=abc] -> 

play.api.db.evolutions.InvalidDatabaseRevision: Database 'default' needs evolution! [An SQL script need to be run on your database.] 
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:424) ~[play_2.9.1.jar:2.0.1] 
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:410) ~[play_2.9.1.jar:2.0.1] 
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) ~[scala-library.jar:0.11.2] 
    at scala.collection.immutable.List.foreach(List.scala:45) ~[scala-library.jar:0.11.2] 
    at play.api.db.evolutions.EvolutionsPlugin.onStart(Evolutions.scala:410) ~[play_2.9.1.jar:2.0.1] 
    at play.api.Play$$anonfun$start$1.apply(Play.scala:60) ~[play_2.9.1.jar:2.0.1] 
    at play.api.Play$$anonfun$start$1.apply(Play.scala:60) ~[play_2.9.1.jar:2.0.1] 
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) ~[scala-library.jar:0.11.2] 
    at scala.collection.immutable.List.foreach(List.scala:45) ~[scala-library.jar:0.11.2] 
    at play.api.Play$.start(Play.scala:60) ~[play_2.9.1.jar:2.0.1] 
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anonfun$1.apply(ApplicationProvider.scala:125) ~[play_2.9.1.jar:2.0.1] 
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anonfun$1.apply(ApplicationProvider.scala:112) ~[play_2.9.1.jar:2.0.1] 
    at scala.Option.map(Option.scala:133) ~[scala-library.jar:0.11.2] 
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3.apply(ApplicationProvider.scala:112) ~[play_2.9.1.jar:2.0.1] 
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3.apply(ApplicationProvider.scala:110) ~[play_2.9.1.jar:2.0.1] 
    at scala.Either$RightProjection.flatMap(Either.scala:277) ~[scala-library.jar:0.11.2] 
    at play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:110) ~[play_2.9.1.jar:2.0.1] 
    at play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:110) ~[play_2.9.1.jar:2.0.1] 
    at akka.dispatch.Future$$anon$3.liftedTree1$1(Future.scala:195) ~[akka-actor.jar:2.0.1] 
    at akka.dispatch.Future$$anon$3.run(Future.scala:194) ~[akka-actor.jar:2.0.1] 
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:83) ~[akka-actor.jar:2.0.1] 
    at akka.jsr166y.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1381) ~[akka-actor.jar:2.0.1] 
    at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) ~[akka-actor.jar:2.0.1] 
    at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:974) ~[akka-actor.jar:2.0.1] 
    at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1478) ~[akka-actor.jar:2.0.1] 
    at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) ~[akka-actor.jar:2.0.1] 

2012-06-28 20:38:30,150 - [WARN] - from play in New I/O server worker #1-1 
Applying evolution script for database 'default': 

# !!! WARNING! This script contains DOWNS evolutions that are likely destructives 

# --- Rev:2,Downs - eddafc8 
delete from admins; 
delete from employees; 

# --- Rev:2,Ups - 822c4da 
insert into admins (username, password) values ('abc', 'abc'); 
insert into admins (username, password) values ('abc', 'abc'); 

insert into employees (id,name,email) values (1, 'Super Man', '[email protected]'); 
insert into employees (id,name,email) values (2, 'Bat man', '[email protected]'); 
insert into employees (id,name,email) values (3, 'Spider Man', '[email protected]'); 
insert into employees (id,name,email) values (4, 'Iron Man', '[email protected]'); 


2012-06-28 20:38:30,741 - [INFO] - from play in play-akka.actor.default-dispatcher-1 
database [default] connected at jdbc:postgresql://localhost/Play 

2012-06-28 20:38:31,519 - [INFO] - from play in play-akka.actor.default-dispatcher-1 
Application started (Dev) 
+1

你列出一個'DATABASE_URL'值,當你運行'的Heroku config'? –

+0

@RyanDaigle是的,我看到了。我試圖使用該網址,但沒有運氣。 – Varundroid

回答

18

看來你是混合了一些播放1播放2個約定。您似乎在使用播放2.播放2最簡單的方法來設置這是在你的application.conf不使用DATABASE_URL,而是僅僅覆蓋數據庫配置在Procfile

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

對於更詳細的步入式通過看我的Play 2 Tutorial

+0

謝謝,我明白了。非常感謝你這麼棒的教程。它會幫助我很多。 – Varundroid

+0

接受答案和+1。 – Varundroid

+0

我在Heroku上部署我的應用程序時遇到了一個奇怪的問題。當我第一次部署它時,一切正常,但是當我第二次部署它時,它給出了應用程序錯誤。我刪除了git,再次使用heroku創建並重新部署它,首先部署 - 工作正常,但第二次部署 - 再次出現應用程序錯誤。我認爲我的進化在這裏做了一些腥意。任何想法可能是什麼原因? – Varundroid

1

使用播放2.4,油滑3.0.3 &的Postgres在Heroku的工作對我來說,運行我的SQL腳本進化以下設置:

在build.sbt:

name := """app-name""" 

,並添加以下在libraryDependencies ++ = SEQ(

"com.typesafe.play" %% "play-slick" % "1.0.1", 
"com.typesafe.play" %% "play-slick-evolutions" % "1.0.1", 
"com.typesafe.slick" %% "slick" % "3.0.3", 
"org.postgresql" % "postgresql" % "9.4-1201-jdbc41", 
"org.slf4j" % "slf4j-nop" % "1.6.4", 

在application.conf:

slick.dbs.default.driver ="slick.driver.PostgresDriver$" 
slick.dbs.default.db.dataSourceClass = "slick.jdbc.DatabaseUrlDataSource" 
slick.dbs.default.db.properties.driver = "org.postgresql.Driver" 

和Procfile:

web: target/universal/stage/bin/app-name -Dhttp.port=${PORT} -Dplay.evolutions.db.default.autoApply=true 

乾杯

相關問題