Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Rails - Make Table With created_at Column

Ruby on rails has the t.timestamps method which creates two columns, created_at and updated_at. How can I make just the created_at column?

This works

class CreateLinesSources < ActiveRecord::Migration
  def change
    create_table :lines_sources do |t|
      t.timestamps null: false
    end
  end
end

Both of these I want to work but fail

class CreateLinesSources < ActiveRecord::Migration
  def change
    create_table :lines_sources do |t|
      t.created_at null: false
    end
  end
end

and

class CreateLinesSources < ActiveRecord::Migration
  def change
    create_table :lines_sources do |t|
      t.timestamps null: false
      remove_column updated_at
    end
  end
end
like image 596
appleLover Avatar asked Aug 15 '15 01:08

appleLover


1 Answers

t.datetime :created_at, null: false

Just like any other column. Rails will still take care of magic updating because of column name.

like image 104
Austio Avatar answered Oct 08 '22 05:10

Austio