Why doesn't this simple Rails migration update my database?

I have a very simple migration that adds one boolean column:

class AddMuteToPreferences < ActiveRecord::Migration
  def self.up
    add_column :preferences, :mute_audio, :boolean, :default => false
  end

  def self.down
    remove_column :preferences, :mute_audio
  end
end

      

I am running the migration:

== 81 AddMuteToPreferences: migrating =========================================
-- add_column(:preferences, :mute_audio, :boolean, {:default=>false})
   -> 1.9043s
== 81 AddMuteToPreferences: migrated (1.9047s) ================================

      

Looks like a peach, doesn't it? But for some reason, there is still no mute_audio column in my preference table.

I can not understand. I have already done add_column with no problem.

Has anyone ever seen this behavior before?

+2


source to share


1 answer


I see no reason why rails cannot add a column. You may be in the wrong database.

The best way to debug this is to enter rails console mode:

script/console development

      



And create a new preference object and give mute_audio a value:

>> p = Preference.new
(...)
>> p.mute_audio = true

      

After the first command, you will see some output containing information about the newly created object. You should see what it has mute_autio: false

. If setting the mute_audio attribute does not throw an error, no problem and a new added column is added.

+3


source







All Articles