-5

I want to add new table using rails migration:

**table_name** users_location_track
**columns** id (primary key, auto increment serial),
            user_id (reference to users), location_info (string), 
            creation_time(time-stamp)

please suggest procedure and code I am new to rails?

piyushmandovra
  • 3,673
  • 2
  • 17
  • 29

2 Answers2

2

In Rails we don't do like you asked. you need to write command like below:

 rails generate migration CreateUserLocationTrack user_id:integer location_info:string 

you don't need creation_time as created_at is created by default.

For more information, please follow rails guide.

Manish Shrivastava
  • 26,075
  • 13
  • 88
  • 100
0

thank you for criticizing. Finally I got my answer:

Here's the solution for whoever want in future.

first go to project directory then run following command

rails generate migration add_user_lat_long

and then a migration file will be generate then you can edit in following style:

class AddUserLatLong < ActiveRecord::Migration
  def self.up
    create_table :users_location_track do |t|
      t.string :location_info
      t.references :user

      t.timestamps

end
    add_index :users_location_track, :user_id, :name =>'index_user_lat_longs_on_user_id'
  end

  def self.down
        drop_table :users_location_track
  end
end
piyushmandovra
  • 3,673
  • 2
  • 17
  • 29