0

here i am trying to customize the column name in mysql. i have generated the model in rails using

rails generate scaffold my_products product_category:string product_name:string 

when i do rake db:migrate the id is generated by default. but i want to change the id column name to product_id,which will be same as ID with primary key, so it will be easy for querying and other manipulation.

How should i do it?

or can i change id to product_id while generating model?

CJAY
  • 6,989
  • 18
  • 64
  • 106

1 Answers1

2

This is how your migration file should look like

class CreateMyProducts < ActiveRecord::Migration
  def change
    create_table :my_products, id: false do |t|
      t.primary_key :product_id
      t.string :product_category
      t.string :product_name

      t.timestamps null: false
    end
  end
end

Make sure you add id: false and set the primary_key as product_id

h0lyalg0rithm
  • 150
  • 1
  • 6