Rails 5 Timestamps Will Be Changed

Rails 5 timestamps will be changed

If you are running Rails 4.2, you will notice the generated migration add a default option to timestamps:

1
2
3
4
5
6
7
8
class CreateFoods < ActiveRecord::Migration
  def change
    create_table :products do |t|

      t.timestamps null: false
    end
  end
end

Without the null: false it will emit a warning:

1
2
3
'#timestamp' was called without specifying an option for `null`. In Rails 5, this behavior will
 change to `null: false`. You should manually specify 'null: true' to prevent the behavior of
 your existing migrations from changing.

This null option is:

:null - allows or disallows NULL values in the column. This option could have been named :null_allowed.

null: false means you cannot give NULL values for created_at and updated_at on Rails 5.

So far so good, That’s it!!! See ya!!! :)