Topic: Remove 'default' values from columns in migrations

How can I keep migrations from adding default values to columns for integer fields? I am using SQLite3 and my migration looks like this:

class CreateWorkOrders < ActiveRecord::Migration
  def self.up
    create_table :work_orders do |t|
      t.column :invoice_number, :integer
      t.column :service_type_id, :integer
      t.column :payment_type_id, :integer
      t.column :location_id, :integer
      t.column :user_id, :integer
      t.column :assignment, :text
      t.column :customer_approval, :string
      t.column :start, :date
      t.column :complete, :date
      t.column :notes, :text
      t.column :payment_info, :text
      t.column :parts_used, :boolean
      t.column :payment_info, :text
      t.column :completed, :boolean
    end
  end

  def self.down
    drop_table :work_orders
  end
end


And here are the resulting directives in schema.rb:

  create_table "work_orders", :force => true do |t|
    t.column "invoice_number",         :integer, :default => 0
    t.column "service_type_id",        :integer, :default => 0
    t.column "payment_type_id",        :integer, :default => 0
    t.column "location_id",            :integer, :default => 0
    t.column "user_id",                :integer, :default => 0
    t.column "assignment",             :text,    :default => ""
    t.column "customer_approval",      :string,  :default => ""
    t.column "start",                  :date
    t.column "complete",               :date
    t.column "notes",                  :text,    :default => ""
    t.column "payment_info",           :text,    :default => ""
    t.column "parts_used",             :boolean, :default => false
    t.column "completed",              :boolean, :default => false
    t.column "travel_time",            :float,   :default => 0.0
    t.column "customer_approval_date", :string,  :default => ""
  end

So now 'WorkOrder.new' creates:

#<WorkOrder:0x3aa0c08
@attributes=
  {"travel_time"=>0.0,
   "completed"=>false,
   "payment_type_id"=>0,
   "customer_approval_date"=>"",
   "assignment"=>"",
   "customer_approval"=>"",
   "service_type_id"=>0,
   "notes"=>"",
   "location_id"=>0,
   "invoice_number"=>0,
   "start"=>nil,
   "payment_info"=>"",
   "complete"=>nil,
   "user_id"=>0,
   "parts_used"=>false},
@new_record=true>

And puts zeros in all of the text_fields in my views, but I want nil values for the integer fields and blank text_fields in the HTML.

I thought about how mothers feed their babies with tiny little spoons and forks, so I wondered what do Chinese mothers use. Toothpicks?

Re: Remove 'default' values from columns in migrations

That sounds an awful lot like a bug.  Have you tried upgrading to Edge? ("rake freeze_edge").  If it still doesn't work i recommend filing a ticked on the dev.rubyonrails.org trac.

Re: Remove 'default' values from columns in migrations

Sounds like a bug indeed, I've never had this happen to me..

Re: Remove 'default' values from columns in migrations

danger wrote:

That sounds an awful lot like a bug.  Have you tried upgrading to Edge? ("rake freeze_edge").  If it still doesn't work i recommend filing a ticked on the dev.rubyonrails.org trac.

That was my take on it as well. The current deployment is using an older revision of Edge and doesn't have the problem. Perhaps I'll roll the trunk back to that revision or freeze to the current HEAD and see if that fixes the issue.

I thought about how mothers feed their babies with tiny little spoons and forks, so I wondered what do Chinese mothers use. Toothpicks?