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 3 如何在使用Rails迁移创建表时添加created_at和updated_at_Ruby On Rails 3_Ruby On Rails 4_Activerecord_Rails Migrations - Fatal编程技术网

Ruby on rails 3 如何在使用Rails迁移创建表时添加created_at和updated_at

Ruby on rails 3 如何在使用Rails迁移创建表时添加created_at和updated_at,ruby-on-rails-3,ruby-on-rails-4,activerecord,rails-migrations,Ruby On Rails 3,Ruby On Rails 4,Activerecord,Rails Migrations,这不会将created_at和update_at添加到迁移中。有没有办法生成迁移并将时间戳添加为参数 Rails g migration CreateFoo时间戳不起作用。似乎这些时间戳只能通过模型自动生成 否则,您可以使用t.timestamps或add\u timestamps:foo将其手动添加到create中,以更改现有表。您需要销毁该表并重新生成 Rails g migration CreateFoo 并检查生成的迁移文件是否存在timestampmethods。如果没有,那么就这样

这不会将created_at和update_at添加到迁移中。有没有办法生成迁移并将时间戳添加为参数


Rails g migration CreateFoo时间戳
不起作用。

似乎这些时间戳只能通过模型自动生成


否则,您可以使用
t.timestamps
add\u timestamps:foo
将其手动添加到
create
中,以更改现有表。

您需要销毁该表并重新生成

Rails g migration CreateFoo
并检查生成的迁移文件是否存在
timestamp
methods。如果没有,那么就这样放

Rails g migration CreateFoo
编辑更新

您可以使用任意一种语法

t.timestamps


希望能有所帮助。

您可以通过以下操作添加时间戳:-

t.timestamps is just an abstract form of writing.
t.timestamps is just an abstract form of writing.
change_table :table_name do |t|
  t.timestamps
end