rails generate model User email:string password:string
creates the following migration script
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :email
t.string :password
t.timestamps
end
end
def self.down
drop_table :users
end
end
What is timestamps and why is it getting created, when I didn’t ask it to be created?
Rails automatically adds two columns,
created_atandupdated_atto your table/migration/ActiveRecord model. If you don’t want them you can remove them.Doing stuff for you automatically that you “didn’t ask it” is what Rails is good at: this is “convention over configuration (CoC).” You can (almost) always specify that you want something else, but in general, Rails will do stuff the way most users want it.
Created and updated timestamps are generally very useful.