为什么在迁移没有时间戳时会创建created

编程入门 行业动态 更新时间:2024-10-21 06:29:19
为什么在迁移没有时间戳时会创建created_at / updated_at?(Why do created_at/updated_at get created when migration does not have timestamps?)

我使用rails 3.2进行以下迁移,并且created_at / updated_at都生成了。 我的印象是添加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

I'm using rails 3.2 with the following migration and created_at/updated_at both get generated. I was under the impression that adding t.timestamps was what caused those columns to get generated.

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

最满意答案

请删除该表并再次检查

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).

参考这个

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

更多推荐

本文发布于:2023-04-29 12:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336327.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时会   时间   created

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!