如何在f.datetime_select的现有数据库中添加列?

时间:2019-03-01 14:07:10

标签: ruby-on-rails

我有一个现有的db(Posts),现在我想在其中添加f.datetime_select的列,我需要运行哪些命令?

rails g migration add_datetime_to_posts datetime:string

2 个答案:

答案 0 :(得分:0)

首先,DateTime是RoR中的一个类(请参见this link),您应该为列指定另一个名称,我将其命名为example

现在,逐步介绍:

rails g migration add_datetime_to_posts example:datetime # create the migrate, added a example column to Posts, the type is datetime
rails db:migrate # execute all pending migrations

运行此命令后,您将在Post资源中拥有example日期时间字段。

答案 1 :(得分:0)

要添加列datetime_select运行,

rails g migration add_datetime_select_to_posts DatetimeSelect:string
相关问题