简体   繁体   English

为什么在没有时间戳的情况下创建created_at / updated_at?

[英]Why do created_at/updated_at get created when migration does not have timestamps?

I'm using rails 3.2 with the following migration and created_at/updated_at both get generated. 我正在使用Rails 3.2进行以下迁移,并且都生成了created_at / updated_at。 I was under the impression that adding t.timestamps was what caused those columns to get generated. 我的印象是,添加t.timestamps是导致生成这些列的原因。

class CreateContactsCountries < ActiveRecord::Migration
  def change
    create_table :contacts_countries do |t|
      t.string :name, :official_name, :null => false
      t.string :alpha_2_code, :null => false, :limit => 2
      t.string :alpha_3_code, :null => false, :limit => 3
    end

    add_index :contacts_countries, :alpha_2_code
  end
end

Please delete the table and check again becuase 请删除表格,然后再次检查,因为

By default, the generated migration will include t.timestamps (which creates 
the updated_at and created_at columns that are automatically populated 
by Active Record).

Ref this 引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM