Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby ActiveRecord Basics Migrations and Relationships Migrations 2

Sebastian Bachmann
Sebastian Bachmann
7,046 Points

Deep Dive: Active Record

Hi,

i am stuck, this is my code:

rails generate migration add_first_name_and_last_name_to_contacts :contacts first_name:string last_name:string

The error message says that the first argument has to be the table name, so contacts is the table name and the first argument. I am not really sure what the problem is.

Thank you in advance!

Regards, Sebastian

4 Answers

Roberto Alicata
PLUS
Roberto Alicata
Courses Plus Student 39,959 Points

I got it...

rails generate migration contacts first_name:string last_name:string
Alan Johnson
Alan Johnson
7,625 Points

Try this one:

rails generate migration add_first_name_and_last_name_to_contacts first_name:string last_name:string

When you create the table you include the table name as a first argument in the list after the migration name, but when changing tables you don't.

Roberto Alicata
PLUS
Roberto Alicata
Courses Plus Student 39,959 Points

I tried with this:

rails generate migration CreateContacts first_name:string last_name:string

and it generates this migration which is identical to the one on the previous challenge:

class CreateContacts < ActiveRecord::Migration
  def change
    create_table :contacts do |t|
      t.string :first_name
      t.string :last_name
    end
  end
end

.... but it doesn't works