2012-02-03 67 views
-1

我最近添加了devise confirmable模塊到我的rails應用程序。我的應用程序在dev中運行良好。但是,當我將它推向heroku時,它會說:「我們很抱歉,但出了問題。」以下是我的英雄日誌 -heroku rails應用程序數據庫遷移問題

Rendered devise/confirmations/new.html.erb within layouts/application (2.7ms) 
2012-02-03T01:55:07+00:00 app[web.1]: Rendered devise/shared/_links.erb (0.5ms) 
2012-02-03T01:55:07+00:00 app[web.1]: cache: [GET /users/confirmation/new] miss 
2012-02-03T01:55:07+00:00 app[web.1]: Completed 200 OK in 19ms (Views: 16.9ms | ActiveRecord: 0.0ms) 
2012-02-03T01:55:07+00:00 heroku[router]: GET personaldiary.herokuapp.com/users/confirmation/new dyno=web.1 queue=0 wait=0ms service=42ms status=200 bytes=1540 
2012-02-03T01:55:11+00:00 app[web.1]: 
2012-02-03T01:55:11+00:00 app[web.1]: 
2012-02-03T01:55:11+00:00 app[web.1]: Started POST "https://stackoverflow.com/users/confirmation" for 50.131.164.83 at 2012-02-03 01:55:11 +0000 
2012-02-03T01:55:11+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"iVVTpWgIrBTR8b9k07lr2tYDFQfAYD0R8JmGVkmfzl4=", "user"=>{"email"=>"[email protected]"}, "commit"=>"Resend confirmation instructions"} 
2012-02-03T01:55:11+00:00 app[web.1]: Processing by Devise::ConfirmationsController#create as HTML 
2012-02-03T01:55:11+00:00 app[web.1]: Completed 500 Internal Server Error in 4ms 
2012-02-03T01:55:11+00:00 app[web.1]: 
2012-02-03T01:55:11+00:00 app[web.1]: NameError (undefined local variable or method `confirmed_at' for #<User:0x000000023254e0>): 
2012-02-03T01:55:11+00:00 app[web.1]: 
2012-02-03T01:55:11+00:00 app[web.1]: cache: [POST /users/confirmation] invalidate, pass 
2012-02-03T01:55:11+00:00 app[web.1]: 

很明顯,該數據庫沒有「confirmed_at」列。我的遷移文件如下:

class AddConfirmableToDeviseV1 < ActiveRecord::Migration 
    def up 
    add_column :users, :confirmation_token, :string 
    add_column :users, :confirmed_at, :datetime 
    add_column :users, :confirmation_sent_at , :datetime 

    add_index :users, :confirmation_token, :unique => true 
    end 

    def down 
    remove_index :users, :confirmation_token 

    remove_column :users, :confirmation_sent_at 
    remove_column :users, :confirmed_at 
    remove_column :users, :confirmation_token 
    end 
end 

我的產量在Heroku託管:

於是我就

heroku run rake db:migrate 

它給了我無輸出。

然後我跑

heroku run rake db:rollback 

它給了我

== AddConfirmableToDeviseV1: reverting ======================================= 
-- remove_index(:users, :confirmation_token) 
rake aborted! 
An error has occurred, this and all later migrations canceled: 

Index name 'index_users_on_confirmation_token' on table 'users' does not exist 

Tasks: TOP => db:rollback 

此外,

heroku run rake db:migrate --trace 

給了我以下

** Invoke db:migrate (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Invoke db:load_config (first_time) 
** Invoke rails_env (first_time) 
** Execute rails_env 
** Execute db:load_config 
** Execute db:migrate 
** Invoke db:schema:dump (first_time) 
** Invoke environment 
** Invoke db:load_config 
** Execute db:schema:dump 

任何想法如何解決這個問題?

+0

你可以使用--trace運行db:migrate並查看是否有輸出? – 2012-02-03 03:21:37

+0

**調用分貝:遷移(FIRST_TIME) **調用環境(FIRST_TIME) **執行環境 **調用分貝:load_config(FIRST_TIME) **調用RAILS_ENV(FIRST_TIME) **執行RAILS_ENV **執行DB:load_config **執行分貝:遷移 **調用數據庫:模式:轉儲(FIRST_TIME) **調用環境 **調用數據庫:load_config **執行DB:架構:甩 – riship89 2012-02-03 03:24:03

+0

你有多個應用程序的設置在Heroku? – 2012-02-03 03:32:09

回答

0

問題解決了。

我刪除了我的遷移文件。在遷移改變方法中增加了一個帶devise helper的新遷移文件。

class AddConfirmableToDevise < ActiveRecord::Migration 
    def change 
     change_table(:users) do |t| 
      t.confirmable 
     end 
     add_index :users, :confirmation_token, :unique => true 
    end 
end 

heroku run rake db:migrate 

再次運行遷移和哇......它的工作。我不知道這有什麼意義,但我很高興它的工作。請留下評論,我熱衷於閱讀解釋。

無論如何,謝謝大家。

+0

替換您的database.yml我不知道,但是,似乎Heroku的不支持向上和向下的方法。任何人都可以證實這一點。 – riship89 2012-02-03 07:13:44

1

您肯定需要確保您的遷移已針對生產數據庫運行。

RAILS_ENV=production rake db:migrate 

這假設你的本地環境可以訪問過程的生產數據庫。

(注:這是一個通用的評論 - 不是的Heroku明確的答案 - 「Heroku的運行rake分貝:遷移」顯然是在其上運行的Heroku生產環境遷移的正確方法)

+0

我跑耙db:遷移。它沒有給我什麼。我運行了rake db:rollback。它說。表'用戶'上的索引名稱'index_users_on_confirmation_token'不存在 – riship89 2012-02-03 02:36:49

+0

運行該RAILS_ENV命令的位置在哪裏? – riship89 2012-02-03 03:30:46

+2

這將不再需要因爲Heroku的應該默認爲生產,並將其與自己的 – 2012-02-03 03:55:26