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

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