我陷入了非常奇怪的问题。我的代码中有以下代码SessionsController
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
我正在尝试在我的History
模型中节省登录时间。这在开发环境中运行良好。但是当我将我的工作添加到 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'
请指导我做错了什么?我无法弄清楚,因为在我的开发网站上也有同样的工作原理 在此先感谢