ruby on rails 3 - Automatic ID generation with create! block in model -
i'm trying use following inside model:
create!( :title => entry.title, :link => entry.url, :published_date => entry.published, :entry_id => entry.id, :category => thing, :author => entry.author, :user_id => user.id )
this fails mysql2::error: duplicate entry '0' key 'primary'
when adding past first entry since id column being set 0. there way auto-increment id using above code?
thanks
you should never need manually specify id when creating new instances; rails automatically create auto-incrementing column handle generating unique ids you.
in case, if have tampered id column , changed type, easiest way reset recreate table.
Comments
Post a Comment