Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails创建表迁移是否应该在创建和更新时创建?_Ruby On Rails_Ruby On Rails 4_Activerecord_Rails Migrations - Fatal编程技术网

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