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

David Ker
David Ker
14,439 Points

Migrations 2 code challenge - can't get it to accept an answer

Having issues with the Migrations 2 code challenge...I've tried rails generate migration CreateContacts first_name:string last_name:string, and variations on it, but it keeps saying "The first argument should be the name of the table"...even though it is, through CreateContacts...which matches the default migration in the Migrations 1 code challenge.

Anyone have any hints??

4 Answers

Hi David,

I found errors that you use this variable called "CreateContacts" from the Migration Challenge 1 but Challenge 2, you will find new variable called "contacts"

Question: 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?

Answers: Just remove CreateContacts, you should use just "contacts"

rails generate migration contacts first_name:string last_name:string

But this is actually wrong. If you do so, rails will generate a migration named

datestamp_contact

with

class Contact < ActiveRecord::Migration
  def change
  end
end

in it. Which is certainly not what you want.

Instead using:

rails generate migration AddXXXToContact first_Name:string last_name:string

will generate

class AddXXXToContact < ActiveRecord::Migration
  def change
    add_column :contact, :first_name, :string
    add_column :contact, :last_name, :string
  end
end

You might want to fix the challenge accordingly...

David Ker
David Ker
14,439 Points

That did it, thanks! I thought I had tried using contacts before. Oh well...thanks again!!

Sarah A. Morrigan
Sarah A. Morrigan
14,329 Points

I still get error on

rails generate migration contacts first_name:string last_name:string
rake db:migrate

"Bummer! The fields should be specified with a colon separating the name and the type."

name:type is there.

I am right, and the Code Challenge is wrong.

Sarah A. Morrigan
Sarah A. Morrigan
14,329 Points

nevermind... i did not have to put rake db:migrate