Ruby on rails Rails创建表迁移是否应该在创建和更新时创建?
根据我的经验,Ruby on rails Rails创建表迁移是否应该在创建和更新时创建?,ruby-on-rails,ruby-on-rails-4,activerecord,rails-migrations,Ruby On Rails,Ruby On Rails 4,Activerecord,Rails Migrations,根据我的经验,railsgmigrationcreatetable迁移总是向表中添加时间戳。但事实并非如此: rails g migration CreateFoo bar:references class Foo < ActiveRecord::Migration def change create_table :foos do |t| t.references :bar, index: true end end end railsg迁移Creat
railsgmigration
createtable迁移总是向表中添加时间戳。但事实并非如此:
rails g migration CreateFoo bar:references
class Foo < ActiveRecord::Migration
def change
create_table :foos do |t|
t.references :bar, index: true
end
end
end
railsg迁移CreateFoo-bar:references
类Foo
这是预期的行为吗?Rails 4中是否发生了这种变化
ActiveRecord 4.1.6使用Rails生成模型功能创建模型、迁移和测试/规范:
rails g model CreateFoo-bar:references
这将在迁移中添加时间戳。时间戳仅在生成模型时创建 下面是指南中的一个示例 产生
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :name
t.string :part_number
end
end
end
您将看到,时间戳仅随“g model”自动提供(您实际上可以对模型禁用它)指南中是否说明仅在生成模型时才包括时间戳?
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :name
t.string :part_number
end
end
end
rails g migration --help
rails g model --help