【发布时间】:2018-04-11 18:52:48
【问题描述】:
我接管了一个由其他人建立的网站。我现在正试图在 localhost 上启动并运行它。但是,当我迁移时,看起来以前的开发人员将代码放入可能依赖于已经存在的种子的迁移中。迁移文件如下所示。
def up
add_column :supplies, :color, :string
Supply.where(:title => "Shipped").first.update(:color =>'#e20ce8')
end
def down
remove_column :supplies, :color
end
当我运行 rake db:migrate 时,我在这个文件上遇到的错误是......
rake aborted!
StandardError: An error has occurred, this and all later migrations
canceled:
undefined method `update' for nil:NilClass
我能做些什么来解决这个问题?
【问题讨论】:
-
尝试
update_attributes而不是update -
感激不尽。它有效,是一个简单而优雅的解决方案。
-
np,我会把它作为答案提交
标签: ruby postgresql rake database-migration