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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -