Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby ActiveRecord Basics Migrations and Relationships Migrations 2

Alessandro Barbieri
Alessandro Barbieri
3,053 Points

Create a table and add columns with migration is not working

I'm trying to answer to this on the ActiveRecord course.

"In the last question, we created a table called contacts, with a first_name and last_name string. How could you include both of those fields automatically by using the generator command?"

I tried:

rails generate migration CreateContacts first_name:string last_name:string

Unfortunately I got this: Bummer! The first argument should be the name of the table.

I got the lines from the documentation so I don't know where I went wrong (http://guides.rubyonrails.org/active_record_migrations.html#creating-a-standalone-migration)

2 Answers

Alessandro Barbieri
Alessandro Barbieri
3,053 Points

Apparently the answer is:

rails generate migration contacts first_name:string last_name:string
Christof Baumgartner
Christof Baumgartner
20,864 Points

Thanks a lot for your answer. This was driving me insane. However I couldn't find this in the video before. Also it seems like a bug for me.

Alessandro Barbieri
Alessandro Barbieri
3,053 Points

I see, anyhow wouldn't be my answer also right?

The documentations says: "If the migration name is of the form "CreateXXX" and is followed by a list of column names and types then a migration creating the table XXX with the columns listed will be generated. For example:"

rails generate migration CreateProducts name:string part_number:string

which gives:

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products do |t|
      t.string :name
      t.string :part_number
    end
  end
end