问题描述
我最近在我的rails应用程序中添加了devise可确认的模块。我的应用程序在开发中运行良好。但是,当我把它推到英雄时,它说:我们很抱歉,但是出了问题。以下是我的英雄日志 - 在布局/应用程序(2.7ms)内渲染设计/确认/ new.html.erb
2012-02-03T01:55:07 + 00:00 app [web.1]:渲染设计/共享/ _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]:19ms完成200 OK意见:16.6ms | ActiveRecord:0.0ms)
2012-02-03T01:55:07 + 00:00 heroku [路由器]: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]:在2012年开始POST/ users / confirmation为50.131.164.83 -02-03 01:55:11 +0000
2012-02-03T01:55:11 + 00:00 app [web.1]:参数:{utf8=>✓,authenticity_token =iVVTpWgIrBTR8b9k07lr2tYDFQfAYD0R8JmGVkmfzl4 =,user=> {email=>[email protected]},commit=> ;重新发送确认说明}
2012-02-03T01:55:11 + 00:00 app [web.1]:由Devise :: ConfirmationsController处理#创建为HTML
2012-02-03T01 :55:11 + 00:00 app [web.1]:完成500内部服务器错误4ms
2012-02-03T01:55:11 + 00:00 app [web.1]:
2012-02-03T01:55:11 + 00:00 app [web.1]:NameError(未定义的局部变量或方法`confirm_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]:
很明显,数据库没有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
$ bheroku 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.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 "/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]:
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 end
My production is hosted on heroku:
So I ran
heroku run rake db:migrate
It gave me no output.
Then I ran
heroku run rake db:rollback
It 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:rollback
Also,
heroku run rake db:migrate --trace
gives 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:dump
Any 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 end
Ran the migration again with
heroku run rake db:migrate
And 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应用程序数据库迁移问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!