Ruby on rails 3.1 如何在Rails中将created_at value用作默认值

Ruby on rails 3.1 如何在Rails中将created_at value用作默认值,ruby-on-rails-3.1,Ruby On Rails 3.1,如何将一个数据库表设置为created_at作为默认值。我这样做了,但没有工作,我检查了数据库,代码的值为空 class CreateEvents < ActiveRecord::Migration def change create_table :events do |t| t.string :title t.string :location t.text :description t.date :occurs_on t.string :

如何将一个数据库表设置为created_at作为默认值。我这样做了,但没有工作,我检查了数据库,代码的值为空

class CreateEvents < ActiveRecord::Migration
  def change
   create_table :events do |t|
    t.string :title
    t.string :location
    t.text :description
    t.date :occurs_on
    t.string :code, :default => Event::created_at

    t.timestamps

  end
 end
end
class CreateEventsEvent::created_at
t、 时间戳
结束
结束
结束

您到底采取了哪些步骤?您是否编辑了现有迁移?如果是这样,您是否执行了回滚,然后重新运行迁移?如果您刚刚添加了默认值,那么应该是一个单独的迁移。基本上,您已经到了可以运行rake db:migrateEyes的程度,我确实回滚并迁移了,但是问题是,值不是日期。所以,实际上我的问题是我不知道如何在迁移中引用创建的_,或者我可以一步完成它,或者我需要单独做一些事情。我尝试使用时间戳,但给了我不同于日期的值。