[英]rails 4 ActiveRecord::StatementInvalid
While upgrading rails application from rails3.2 to rails 4. I am getting a issue 将Rails应用程序从rails3.2升级到rails 4时,出现问题
ActiveRecord::StatementInvalid in SessionsController#new
ActiveRecord :: StatementInvalid在SessionsController#new中
Mysql::Error: Field 'session_id' doesn't have a default value: INSERT INTO
sessions
(created_at
,data
,updated_at
) VALUES (?, ?, ?)Mysql :: Error:字段'session_id'没有默认值:INSERT INTO
sessions
(created_at
,data
,updated_at
)VALUES(?,?,?)
In my sessions table I have session_id field, But I don't know how to set default value. 在我的会话表中,我有session_id字段,但是我不知道如何设置默认值。
can u help me to resolve this issue? 您能帮我解决这个问题吗?
my add_sessions_table.rb migration file: 我的add_sessions_table.rb迁移文件:
class AddSessionsTable < ActiveRecord::Migration
类AddSessionsTable <ActiveRecord :: Migration
def change
清晰度变化
create_table :sessions do |t| t.string :session_id, :null => false t.text :data t.timestamps end add_index :sessions, :session_id add_index :sessions, :updated_at end
end
结束
my sessions_store.rb file 我的sessions_store.rb文件
MyApp::Application.config.session_store :active_record_store
MyApp :: Application.config.session_store:active_record_store
Thanks 谢谢
Add this code in an initializer, 将此代码添加到初始化程序中,
ActiveRecord::SessionStore::Session.attr_accessible :data, :session_id
ActiveRecord :: SessionStore :: Session.attr_accessible:data,:session_id
for more info checkout the activerecord-session_store link 有关更多信息,请查看activerecord-session_store链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.