default column values and creating new rows with ActiveRecord

Hello,
I have a table that looks kind of like this:
CREATE TABLE blahs (
id SERIAL PRIMARY KEY,
...
modified_at DATETIME NOT NULL DEFAULT now()
)

When I try to create a new row using ActiveRecord, it bombs saying I'm
not allowed to set modified_at to NULL.

new = Blah.new
new.some_field = some_value
new.save! # ERROR: null value in column "modified_at" violates not-
null constraint (ActiveRecord::StatementInvalid)

Is there any way to let ActiveRecord use the default value set at the
database level?

I'm using Postgres 8.2.

Thanks for the help.

Christopher J. Bottaro wrote:

Hello,
I have a table that looks kind of like this:
CREATE TABLE blahs (
id SERIAL PRIMARY KEY,
...
modified_at DATETIME NOT NULL DEFAULT now()
)

When I try to create a new row using ActiveRecord, it bombs saying I'm
not allowed to set modified_at to NULL.

new = Blah.new
new.some_field = some_value
new.save! # ERROR: null value in column "modified_at" violates not-
null constraint (ActiveRecord::StatementInvalid)

Is there any way to let ActiveRecord use the default value set at the
database level?

I'm using Postgres 8.2.

I'm not sure if you can use the default from the database. But why are you using modified_at instead of updated_at which Rails will handle for you automatically?

Also, if you want to set a default value you could simply do so in a before_save hook:

def before_save
   self.modified_at = Time.now
end