[英]How to arrange the order of columns in a database of a Rails application?
我最近使用Rails遷移添加了:title
列:
class AddTitleToMicroposts < ActiveRecord::Migration
def change
add_column :microposts, :title, :string
end
end
我注意到,當我執行user.microposts時它出現在最后:在控制台中:
=> [#<Micropost id: 1, content: "test", user_id: 1, created_at: "2012-01-25 15:34:30", updated_at: "2012-01-25 15:34:30", title: nil>]
有沒有辦法安排標題欄的順序? 比如說,把它放在:content
列之前?
有一個:after
選項來插入列(不幸的是:after
選項:before
)
class AddTitleToMicroposts < ActiveRecord::Migration
def change
add_column :microposts, :title, :string, :after => :content
end
end
在架構中重新排列它們並執行rake db:schema:load
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.