Forum: Ruby on Rails validates_presence_of

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
rhywun (Guest)
on 2006-12-29 02:10
(Received via mailing list)
I'm confused about the usage of 'validates_presence_of' and the
'default' parameter of the 'column' method. Let's say I have a model
that looks something like this:

  class CreateErrorTypes < ActiveRecord::Migration
    def self.up
      create_table :error_types do |t|
        t.column :description, :string, :limit => 254, :null => false
        t.column :can_delete, :boolean, :null => false, :default =>
    def self.down
      drop_table :error_types

  class ErrorType < ActiveRecord::Base
    validates_presence_of :description
    validates_presence_of :can_delete

Then in console I do this:

  >> ErrorType.create(:description => "General error")

What I expect is an ErrorType object with can_delete set to false, but
what I get is an error saying that can_delete "can't be blank". Why
isn't it setting the default value of that field to false??
This topic is locked and can not be replied to.