6

my User Model looks like:

    class CreateUsers < ActiveRecord::Migration
       def self.up
         create_table :users do |t|
         t.string :name
         t.string :email

         t.timestamps
       end
    end

      def self.down
        drop_table :users
        end
      end

If I wanted add one more :attribute, is it best to create another migration file for adding a new column (see another Stackoverflow thread) or can I just manually add t.string :name_of_new_attribute and then rake db:migrate?

Thanks!

Community
  • 1
  • 1
Elias7
  • 12,285
  • 13
  • 35
  • 35

1 Answers1

16

The proper way is to create a new migration. In the main rails project folder, run

rails generate migration AddDetailsToUser address:string age:integer etc...

and then run rake db:migrate

An alternative to this is to edit the original migration file, reset/destroy the database and re-run all migrations.

JBaczuk
  • 13,886
  • 10
  • 58
  • 86
Norto23
  • 2,249
  • 3
  • 23
  • 40