很明显,数据库没有confirmation_at列。我的迁移文件如下:
class AddConfirmableToDeviseV1< ActiveRecord :: Migration def up add_column:users,:confirmation_token,:string add_column:users,:confirmation_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,,confirmation_at remove_column:users,:confirmation_token end end我的生产主办在heroku上:
所以我跑了
heroku run rake db:migrate没有输出。
然后我跑了
heroku run rake db:rollback pre>它给了我
== AddConfirmableToDeviseV1:reverting == =================================== - remove_index(:users,:confirmation_token ) rake aborted! 发生错误,这个和所有后来的迁移已取消: 表'用户'上的索引名称'index_users_on_confirmation_token'不存在 任务:TOP => ; db:rollback另外,
heroku run rake db:migrate --trace给我下面的
**调用db:migrate(first_time) **调用环境(first_time) **执行环境 **调用db:load_config(first_time) **调用rails_env(first_time) **执行rails_env **执行db:load_config **执行db:migrate **调用db:schema:dump(first_time) **调用环境 **调用db:load_config **执行db:schema:dump任何想法如何解决这个问题?
解决方案解决问题。
我删除了我的迁移文件。在迁移更改方法中添加了一个带有dev助手的新迁移文件。
class AddConfirmableToDevise< ActiveRecord :: Migration def change change_table(:users)do | t | t.confirmable end add_index:users,:confirmation_token,:unique => true end end再次使用
$进行迁移b $ b heroku run rake db:migrate&p ...而且呃...它的工作。我不知道这是如何有意义的,但我很高兴它是有效的。请留言,我热衷于阅读说明。
无论如何,谢谢大家。
I recently added devise confirmable module to my rails app. My application runs well in dev. But, when I push it to heroku, it says "We're sorry, but something went wrong.". Following is my heroku log-
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/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 "/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"=>"hrishikeshp19@gmail"}, "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]:It is clear that the database does not have "confirmed_at" column. My migration file is as follows:
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 endMy production is hosted on heroku:
So I ran
heroku run rake db:migrateIt gave me no output.
Then I ran
heroku run rake db:rollbackIt gave me
== 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:rollbackAlso,
heroku run rake db:migrate --tracegives me following
** 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:dumpAny Ideas how to solve this issue?
解决方案Problem solved.
I deleted my migration files. Added a new migration file with devise helper in migration change method.
class AddConfirmableToDevise < ActiveRecord::Migration def change change_table(:users) do |t| t.confirmable end add_index :users, :confirmation_token, :unique => true end endRan the migration again with
heroku run rake db:migrateAnd whoa...it worked. I do not know how does this make sense, but I am glad that it worked. Please leave comments, I am keen to read explanation.
Anyway, thanks everybody.
更多推荐
heroku rails应用程序数据库迁移问题
发布评论