Mar*_*rco 4 postgresql ruby-on-rails
我找到了一段代码,谁能告诉我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
Run Code Online (Sandbox Code Playgroud)
在 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
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅GitHub 上的原始拉取
| 归档时间: |
|
| 查看次数: |
1012 次 |
| 最近记录: |