我找到了一段代码,有人能让我知道comment:主要用于什么,以及如何在表名和字段上添加注释吗?
我用PostgreSQL。
create_table "sun", force: :cascade, comment: "The center" do |t|
t.string "distance", comment: "Long way"
t.string "energy", comment: "Super power"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end发布于 2016-12-05 02:07:21
在Rails 5中,允许为数据库迁移中的表、列和索引指定注释。这些注释存储在数据库本身中。您正在查看显示注释的schema.rb。
目前只有MySQL和PostgreSQL支持添加注释。
注释就是简单的注释--它们给出了表/列的简短摘要。
要在迁移期间添加注释,只需将comment: 'This is an explanatory comment'添加到迁移中,显然可以替换所需的注释文本。
下面的迁移示例显示了这一点,我在表中添加了一列:
class AddSomethingToSometable < ActiveRecord::Migration
def change
add_column :sometable, :something, :integer, comment: 'This is an explanatory comment'
end
end有关更多信息,请参见原始拉力 on GitHub
https://stackoverflow.com/questions/40966029
复制相似问题