Ruby on rails 插入模型在开发中起作用,但在生产中不起作用
我陷入了一个非常奇怪的问题。我的Ruby on rails 插入模型在开发中起作用,但在生产中不起作用,ruby-on-rails,heroku,Ruby On Rails,Heroku,我陷入了一个非常奇怪的问题。我的sessioncontroller def create user = User.find_by_email(params[:session][:email].downcase) if user && user.authenticate(params[:session][:password]) sign_in user @history=user.histories.build(:TimeLogin =>
sessioncontroller
def create
user = User.find_by_email(params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
sign_in user
@history=user.histories.build(:TimeLogin => Time.now.strftime("%d/%m/%Y %H:%M"))
@history.save
redirect_back_or "/recalls"
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
我试图在我的历史记录
模型中节省登录时间。这在开发环境中运行良好。但是当我将我的工作添加到heroku时,我在日志中得到以下错误
2013-10-29T06:47:29.542675+00:00 app[web.1]: ActiveRecord::StatementInvalid (PGError: ERROR: null value in column "id" violates not-null constraint
2013-10-29T06:47:29.542675+00:00 app[web.1]: DETAIL: Failing row contains (null, 2013-10-29 06:47:00, null, 1, 2013-10-29 06:47:29.533033, 2013-10-29 06:47:29.533033).
2013-10-29T06:47:29.542675+00:00 app[web.1]: : INSERT INTO "histories" ("TimeLogin", "TimeLogout", "created_at", "id", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6)):
2013-10-29T06:47:29.542675+00:00 app[web.1]: app/controllers/sessions_controller.rb:11:in `create'
请告诉我我做错了什么?我无法弄清楚,因为在我的开发站点上也有同样的功能
提前感谢我通过添加
设置主键:id
对于我的模型,在迁移过程中,我创建了
id
asSERIAL
可能ActiveRecord在CamelCase
字段名方面存在问题?不过我只是猜测一下,因为错误表明id
列丢失了。这是否有帮助?nathanvda我已经看到了该链接。我的情况并非如此,因为我检查并比较了我的历史模式。我猜我给了一些null,value,试图弄清楚。通常你自己从来不填写id,所以我猜它是在你的模式中定义错误的地方。除非您通常自己填写id,否则您也会在开发中填写id。在本例中,开发和生产之间的唯一区别是数据库。错误清楚地表明id
为空。您是否可以在问题中添加历史迁移。。。