Re: ActiveRecord uses confusing defaults

Jeroen Houben
Sat, 09 Sep 2006 19:22:22 -0000

Al Evans wrote:
> Jeroen wrote:
>
>> class AddTestTable < ActiveRecord::Migration
>>   def self.up
>>     create_table "contents", :force => true do |t|
>>       t.column "email", :string, :null => false
>>     end
>>   end
>>
>>   def self.down
>>     drop_table "contents"
>>   end
>> end
>>
>> $ script/generate model Content
>>
>> $ script/console
>>
>> Loading development environment.
>>>> Content.new.email
>> => ""
>>>>
>>
>> I just dont understand why it defaults to "" and not to nil.
Nowhere did
>> I set the default to "" in my migrations file.
>
> It has to default to something.

Well in Mysql I *can* set an integer column to NOT NULL and not specify
a default value. It''s a valid SQL schema. I think AR should copy this
behaviour and not force a default zero, but I seem to stand alone in
this. It''s no biggy really, just wanted to see what the idea behind
this
AR behaviour was. Thanks!

Jeroen