为什么在迁移没有时间戳时会创建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 endI'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
更多推荐
发布评论