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 Relationships

Jennifer Crawshaw
Jennifer Crawshaw
17,878 Points

Schema not matching with Time Entry model

I am unable to add time entries to a customer. When I compared my TimeEntry model to the schema, they do not match up, even after running 'rake db:migrate'

class CreateTimeEntries < ActiveRecord::Migration
  def change
    create_table :time_entries do |t|
      t.float :time
      t.belongs_to :customer
      t.belongs_to :employee
      t.timestamps
    end
  end
end
create_table "time_entries", force: true do |t|
    t.datetime "created_at"
    t.datetime "updated_at"
  end

Any help is appreciated!

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Please give us more details. What steps did you take to create all your models and migrations? How does your schema look like and what doesn't match exactly? Can you link videos that instructed you what to do?

3 Answers

This happened to me, too! The reason was that I forgot to save my file before my rake db:update. I fixed it by:

  • `rake db:rollback two times
  • "editing" all of the files (basically, I added a space, deleted that space, and then saved the file)
  • running rake db:migrate again.

So basically, I rolled it back, made sure to edit/save the files, and then said "hey run this again!"

Hope this helps!

Jennifer Crawshaw
Jennifer Crawshaw
17,878 Points

I was working through the lesson on Active Record Basics. My schema is the code on the bottom screen of my original post.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Do you have any other migrations in the db/migrate folder? I could look at your whole code and see how the app behaves if you could publish it on GitHub.

Kyle Daugherty
Kyle Daugherty
16,441 Points

By chance, did you edit your migration file after you already ran rake db:migrate? If so, you need to rollback your changes or just create a new migration to add the additional columns you're needing.