ActiveRecord is one of the most useful utilities in the Rails toolkit. It allows us to perform complex database queries while abstracting the adapter, essentially making a database “pluggable”.

However, some edge cases stand out like a sore thumb. One such query is the ability to set values to the standard Rails timestamps which are available across models. Namely, created_at, created_on, updated_at, updated_on.

In a typical model insertion, one does not need to actively set values for the timestamps. They are set by the underlying framework at the time of insertion.

### Before

One would expect consistent action across similar queries. Let’s have a look at mass insertion queries.

It raises an unexpected exception ActiveRecord::NotNullViolation, since a database constraint is present on the created_at column. This leaves us with only one option — manually providing values for all timestamp columns.

The only way to make this work is,

### After

We have the option to override this configuration using,

Which, as expected, will result in the previous error.