耙子流产了! NameError:未初始化的常量UpdateDateOnReservations

时间:2016-06-25 21:32:19

标签: ruby-on-rails ruby migration

此迁移是从不久前开始的,直到现在才引发问题。我不知道我做错了什么。以下是整个错误消息:

Hiras-MacBook-Pro:seatyourself hirakazmi$ 
  be rake db:migrate rake aborted!

  NameError: uninitialized constant UpdateDateOnReservations
  /Users/hirakazmi/.rbenv/versions/2.3.1/bin/bundle:22:in `load'
  /Users/hirakazmi/.rbenv/versions/2.3.1/bin/bundle:22:in `<main>'

  NameError: uninitialized constant UpdateDateOnReservations
  /Users/hirakazmi/.rbenv/versions/2.3.1/bin/bundle:22:in `load'
  /Users/hirakazmi/.rbenv/versions/2.3.1/bin/bundle:22:in `<main>'

  Tasks: TOP => db:migrate (See full trace by running task with --trace)

Hiras-MacBook-Pro:seatyourself hirakazmi$ 

1 个答案:

答案 0 :(得分:2)

我假设您有一个名为db/migrations/20160000000000_update_date_on_reservations.rb的rails迁移文件。在该文件中,您的类名与文件名不匹配。

该迁移文件应该定义类如下:

class UpdateDateOnReservations < ActiveRecord::Migration

  def change
    add_column :reservations, :updated_date, :datetime
  end

end

如果这不能解答您的问题,请使用--trace运行您的命令,例如:be rake db:migrate --trace,并在此处或在要点中发布结果。