Losing Default Value with Migration

0 views
Skip to first unread message

dennis baldwin

unread,
Jun 22, 2007, 12:03:26 PM6/22/07
to Ruby on Rails: Talk
Hi,

I'm wondering if anyone has experienced problems with losing default
column values when running a migration. I have a column that defaults
to a value of 0, yet when I run a migration I lose the default value
which reverts to NULL. My migration is simple:

class RenameRecentLocationId < ActiveRecord::Migration
def self.up
rename_column :devices, :recent_location_id, :recent_reading_id
end

def self.down
rename_column :devices, :recent_reading_id, :recent_location_id
end
end

Am I missing something or is this a known issue? Thanks in advance
for any light you can shed on the problem.

Best regards,
Dennis

dennis baldwin

unread,
Jun 22, 2007, 12:18:30 PM6/22/07
to Ruby on Rails: Talk
Okay, so it seems I should do a change_column after the rename. Sorry
for the waste of bytes and I was expecting Rails to do everything for
me with one line of code :)

class RenameRecentLocationId < ActiveRecord::Migration
def self.up
rename_column :devices, :recent_location_id, :recent_reading_id

change_column :devices, :recent_reading_id, :integer, :default =>
0
end

def self.down
rename_column :devices, :recent_reading_id, :recent_location_id

change_column :devices, :recent_location_id, :integer, :default =>
0
end
end

Reply all
Reply to author
Forward
0 new messages