Adding a column to an existing table in a Rails migration

I have a Users model which needs an :email column (I forgot to add that column during the initial scaffold).

I opened the migration file and added t.string :email, did rake db:migrate, and got a NoMethodError. Then I added the line

add_column :users, :email, :string

again rake db:migrate, again NoMethodError. Am I missing a step here?

Edit: here’s the migration file.

class CreateUsers < ActiveRecord::Migration  
  def self.up  
    add_column :users, :email, :string  
    create_table :users do |t|  
      t.string :username  
      t.string :email  
      t.string :crypted_password  
      t.string :password_salt  
      t.string :persistence_token  

      t.timestamps  
    end  
  end  

  def self.down  
    drop_table :users  
  end  
end

11 Answers
11

Leave a Comment