Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does timestamps get created while generating the model

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?

like image 477
Jason Avatar asked Sep 10 '11 08:09

Jason


1 Answers

This question came up in a search for "generate rails model without timestamps" so I wanted to add an answer on how to do that:

rails g model MyModel --no-timestamps

This works in Rails 3.2+.

like image 107
Peter Brown Avatar answered Oct 10 '22 18:10

Peter Brown