[英]ActiveRecord::StatementInvalid PG::UndefinedColumn: ERROR
[英]ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR
嘗試運行rake db:migrate
時出現錯誤:
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "plus_ids" of relation "comments" does not exist
我想在嘗試從評論模型中刪除屬性plus_ids時確實做了一些時髦的事情。 我不確定發生了什么。
如果我執行rake db:reset
然后獲取實時數據庫,則所有這些都將再次在本地工作,但是如果我嘗試執行rake db:migrate
它將再次引發錯誤。
如何正確去除plus_ids以便遷移?
編輯1:這是我添加(和刪除)屬性后的遷移文件:
class RemovePlusIdsFromComments < ActiveRecord::Migration
def change
remove_column :comments, :plus_ids, :integer
end
end
接着
class AddPlusIdsToComments < ActiveRecord::Migration
def change
add_column :comments, :plus_ids, :integer
end
end
它們在遷移列表中的順序錯誤,不確定原因。
編輯2:我認為上/下有問題,如果我運行rake db:migrate:status
我會得到:
down 20150305203336 Remove plus ids from comments
down 20150305204404 Add plus ids to comments
可以解決嗎?
答案是跑
rake db:migrate:up VERSION=20150305204404
在現場和本地,然后
rake db:migrate
再次上。 現在,實時數據庫和本地數據庫再次同步,並且遷移數據庫不會引發任何錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.