Search code examples
rubypostgresqlrakedatabase-migration

rake db:migrate runs into an error for an undefined method


I took over a website that was built by somebody else. I'm now trying to get it up and running on localhost. However, when I migrate it looks like the previous developer put code into the migrations that may rely on a seed already being there. The migrate file looks like this.

def up
  add_column :supplies, :color, :string

  Supply.where(:title => "Shipped").first.update(:color =>'#e20ce8')
end

def down
  remove_column :supplies, :color
end

The error I get on this file when i run rake db:migrate is...

rake aborted!
StandardError: An error has occurred, this and all later migrations 
canceled:

undefined method `update' for nil:NilClass

What can I do to fix this?


Solution

  • What about doing rake db:schema:load? I believe that would allow you to get going and then allow you to use rake db:migrate going forward.