views:

77

answers:

3

Low sleep so probably missing something trivial, but...

Based on various doc readings, I thought that this would generate a migration with table and column declarations included...

$ script/generate migration Question ordinal_label:string question_text:string

However, the result is...

class Question < ActiveRecord::Migration
  def self.up
  end

  def self.down
  end
end

Why is there no table or columns?

+1  A: 

That should be

$ script/generate model Question ordinal_label:string question_text:string

You will also end up with a model, unit test and fixture of course. script/generate with migrate will add a column to an existing table but not to a new one.

$ script/generate migration add_question_text_to_question question_text:string
JosephL
A: 

You need a verb if you are modifying a model.

script/generate migration AddLabelToQuestion label:string

or to generate a new model, you use your statement above, but substitute migration for model.

LymanZerga
+4  A: 

The script/generate migration command does not create columns on new tables.

Only if you wish add, for instance, a column to an existing table you can pass the new column as an argument:

script/generate migration add_text_to_question question_text:string

For what you are trying to achieve you have to create a new model:

script/generate model Question ordinal_label:string question_text:string

This will generate a migration like the following:

class CreateQuestions < ActiveRecord::Migration
    def self.up
      create_table :questions do |t|
        t.string  :ordinal_label
        t.string  :question_text
        t.timestamps
      end
    end

    def self.down
      drop_table :questions
    end
  end
rogeriopvl