簡體   English   中英

如何安排Rails應用程序的數據庫中的列順序?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM