Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Relationships

Jorge Garcia
Jorge Garcia
6,496 Points

rake aborted! StandardError:

This is what I get when i try to "bin/rake db:migrate". Any help would be greatly appreciated.

[DEPRECATION] last_comment is deprecated. Please use last_description instead. [DEPRECATION] last_comment is deprecated. Please use last_description instead. [DEPRECATION] last_comment is deprecated. Please use last_description instead. [DEPRECATION] last_comment is deprecated. Please use last_description instead. [DEPRECATION] last_comment is deprecated. Please use last_description instead. [DEPRECATION] last_comment is deprecated. Please use last_description instead. [DEPRECATION] last_comment is deprecated. Please use last_description instead. [DEPRECATION] last_comment is deprecated. Please use last_description instead. == CreateTodoItems: migrating ================================================ -- create_table(:todo_items) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:

undefined method reference' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0xbadb3674> /home/treehouse/projects/odot/db/migrate/20160508194053_create_todo_items.rb:4:inblock in change' /home/treehouse/projects/odot/db/migrate/20160508194053_create_todo_items.rb:3:in `change' Tasks: TOP => db:migrate (See full trace by running task with --trace)

Here is line 1-10 of the file 20160508194053_create_todo_items.rb

class CreateTodoItems < ActiveRecord::Migration
  def change
    create_table :todo_items do |t|
      t.reference :todo_list, index: true
      t.string :content

      t.timestamps
    end
  end
end

2 Answers

Seth Kroger
Seth Kroger
56,361 Points

The error is happening because you used t.reference instead of t.references plural. It also looks like you're missing some things from the migration file. This is what I have in my saved project.

class CreateTodoItems < ActiveRecord::Migration
  def change
    create_table :todo_items do |t|
      t.references :todo_list, index: true, foreign_key: true
      t.string :content

      t.timestamps null: false
    end
  end
end
Jorge Garcia
Jorge Garcia
6,496 Points

Thant did it. Thank you Seth!