0
== AddAncestryToMessages: migrating ==========================================
-- add_column(:messages, :ancestry, :string)
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: no such table: messages: ALTER TABLE "messages" ADD "ancestry" varchar(255)
所以我的應用程序有消息,你可以發佈(有點像twitter)和我添加回復,我使用祖先的寶石這樣做。爲什麼我在嘗試運行rake db時遇到此錯誤:migrate?
我在我的schema.rb
文件中的代碼(我認爲這是使用它來創建表每次運行耙分貝時刻的文件:!遷移,但我可能是錯的(這可能是問題)
create_table "messages", :force => true do |t|
t.string "content"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "ancestry"
end
add_index "messages", ["user_id", "created_at", "ancestry"], :name => "index_messages_on_user_id_and_created_at_and_ancestry"
嗯,沒有爲我工作。我從add_index方法中取出t.string「血統」和「血統」,因此將其更改回原始狀態。然後我運行rails遷移CreateMessages,併爲我創建了rb文件。然後我複製並粘貼上面的所有代碼。這是否正確? – BigBoy1337
等一下。 *將其更改回原來的狀態* - 您的意思是什麼?你已經有了桌子,只想添加索引到它?如果你只需要在表中添加一個索引,那麼你的'up' /'change'方法應該只包含'add_index ....'。另外,如果你有'up'方法,那麼用'remove_index,:name =>「...」'填充'down'方法。 – jdoe
@ user1123905,幾乎正確。在新的rb文件中,你應該調用add_column和add_index,因爲jdoe指出,你已經有了表。 –