Rails not using default database value when saving model

I setup a migration with a table that has a default value and can not be
null.

create_table( :user ) do |t|
t.column( :first_name, :string, {null => false} )
t.column( :last_name, :string, {null => false} )
t.column( :email_address, :string, {null => false} )
t.column( :last_login, :datetime, {:default => ‘now()’, :null =>
false} )
end

It creates the table. If I view it from within mysql, It has the
default value. However, when I go to create a record it fails.

User.create( :first_name => “first”,
:last_name => “last”,
:email_address => “[email protected]” )

I see that the sql statement rails makes sets last_login to NULL. How
can I get rails to use the default value in this situation?

Thanks!
Chris

t.column( :last_login, :datetime, {:default => ‘now()’, :null =>
false} )

You’re setting a Ruby string here; I guess the AR code doesn’t pass SQL
expressions around, instead only uses raw data. So its either a fixed
date object for all instances or its nothing.

Your solution for today is to take responsibility for setting the date
object yourself.

Perhaps raise a core ticket (if Trac is working).

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs