How can I create a table where the my :id
field will not auto-increment?
Example table:
cost_categories
id description
-- -----------
94 Labor
101 Framing
750 Paint
Please Note: As far as my :id
column goes, everything about it will be th开发者_高级运维e Rails default accept the fact that I don't want it to auto-increment.
I've seen a lot of answers where they suggest not doing this, but it doesn't make sense to have, say, a rails default :id
field AND my own :cc_id
field.
I'd really appreciate any assistance.
For mysql DB: In your migration file:
create_table :table_name, :id => false do |t|
t.integer :id, :options => 'PRIMARY KEY'
end
YOu should add your index:
add_index(:table_name, :id, :unique => true, :name => 'id_index')
精彩评论