ActiveRecord+SQLite3で id という名前のカラムを入れられない
予約語か何かなのかな?
問題の箇所。idというcolumnを用意して
class StatsInit < ActiveRecord::Migration def self.up create_table :stats do |t| t.column :id, :string, :limit => 12, :null => false t.column :name, :string, :limit => 20, :null => false t.column :text, :string, :limit => 200, :null => false end end def self.down drop_table :stats end end
createすると
class Stat < ActiveRecord::Base end Stat.create( :id => '1234556', :name => 'zanmai', :text => '肉が食べたい' )
エラーが出て落ちる
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2313:in `remove_attributes_protected_from_mass_assignment': undefined method `debug' for nil:NilClass (NoMethodError)
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2114:in `attributes='
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1926:in `initialize'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:571:in `new'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:571:in `create'idって名前をやめたら通った。_idとでもしてみた。