I have a model in whose migration I have defined a datetime column that
both has a default value and sets null to false. As this is a
PostgreSQL database the default value is ‘infinity’, which may be the
source of the difficulty.
When I attempt to save this model ActiveRecord produces an SQL statement
that explicitly sets this column to NULL thus both defeating the purpose
of the default value and triggering the NOT NULL constraint on the DBMS.
How does one turn off or override this behaviour? What I want to happen
is that model_instance.save will only specify columns that have values
set and will simply not include any column that does not have an
explicit value set.
I can see that for other attributes ActiveRecord is setting things to
the defaults provided in the migration. Is this the case? If not then
where is ActiveRecord getting this information? And why bother? The
purpose of a default value on a database column is to have the DBMS
provide for the absence of information at the DBMS level. If I wish to
do that at the attribute level then I can do so in the model class
I have tested the attribute in question immediately before the call to
save and #attribute_present?( :column ) == false, so I am not
inadvertently setting this column to null or nil somewhere else in my