我有一個Rails應用程序一個sqlite3的分貝以下架構remove_column不列刪除或提供在軌
ActiveRecord::Schema.define(:version => 20100816231714) do
create_table "comments", :force => true do |t|
t.string "commenter"
t.text "body"
t.integer "post_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "posts", :force => true do |t|
t.string "name"
t.string "title"
t.text "content"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "tags", :force => true do |t|
t.string "name"
t.integer "post_id"
t.datetime "created_at"
t.datetime "updated_at"
end
end
我一開始的帖子任何錯誤:的has_many關係與標籤,以便每個標籤都有一個POST_ID參考。
我現在想這種關係更改爲「has_and_belongs_to_many」,我知道我必須要創建連接的表等....這不是一個問題,並正在
在問題出現時,我嘗試從標籤表中刪除post_id表單。我的遷移是這樣的:
class RemoveFieldsToTags < ActiveRecord::Migration
def self.up
remove_column :tags, :post_id
end
def self.down
add_column :tags, :post_id, :references
end
end
當我運行耙分貝:遷移和耙分貝:遷移:後續版本=沒有任何反應,當我運行耙分貝:遷移:縮小版本=我得到柱:
SQLite3::SQLException: duplicate column name: post_id: ALTER TABLE "tags" ADD "post_id" references
任何人都知道發生了什麼事?
歡呼的答案,我開始使用has_many:through關係,但決定增加了一些不必要的複雜性(我將簡單化),關於這種關係的官方立場似乎是'當你想保留時使用關於連接的信息'例如。關係的時間是作出,結果等... – zode64 2010-08-17 18:09:29
這工作的方式,謝謝 – zode64 2010-08-17 19:35:33