Losing Default Value with Migration

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

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 :slight_smile:

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

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